这是一张图片:
附录:我希望这张图片能让你更清楚地了解问题所在。
我有一个水平导航菜单,项目之间的间距相等...但我需要它们之间有不同的间距。例如,“艺术/插图”和“接触”之间的间距应该比“室内设计”和“艺术/插图”之间的间距更大。有什么建议可以实现吗?
https://codepen.io/abudimir/pen/bXVdxW
我试着玩填充和页边距,但所有的项目都移动了。我尝试为这些项添加一个单独的类,但是所有的项都会移动。
/* the whole menu */
#menu {
text-align: center;
width: 100%;
margin: 0;
}
/* Horizontal list menu */
.top-link {
display: inline-block;
float: none;
position: relative;
font-size: 1.5rem;
font-weight: bolder;
}
/*Style for menu links*/
.top-link a {
display: block;
/* links fill the block*/
color: var(--text-color);
width: 100%;
padding: 1.2em 2.7em;
line-height: 1rem;
text-align: center;
}
/*Hover state for top level links*/
.top-link:hover a {
background: red;
color: rgb(255, 255, 255);
}
<nav>
<ul id="menu">
<li class="top-link">
<a href="about.html">About</a>
</li>
<li class="top-link">
<a href="#">Graphical Design</a>
</li>
<li class="top-link">
<a href="#">Interior Design</a>
</li>
<li class="top-link">
<a class="a3" href="#">Arts / Illustrations</a>
</li>
<li class="top-link">
<a href="contact.html">Contact</a>
</li>
</ul>
</nav>
发布于 2019-07-22 12:47:59
ul li:last-child {
margin-left: 50rem;
}
这应该是可行的。
/* the whole menu */
#menu {
text-align: center;
width: 100%;
margin: 0;
}
/* Horizontal list menu */
.top-link {
display: inline-block;
float: none;
position: relative;
font-size: 1.5rem;
font-weight: bolder;
}
/*Style for menu links*/
.top-link a {
display: block; /* links fill the block*/
color: var(--text-color);
width: 100%;
padding: 1.2em 2.7em;
line-height: 1rem;
text-align: center;
}
/*Hover state for top level links*/
.top-link:hover a {
background: red;
color: rgb(255, 255, 255);
}
ul li:last-child {
margin-left: 50rem;
}
<nav>
<ul id="menu">
<li class="top-link"> <a href="about.html">About</a> </li>
<li class="top-link">
<a href="#">Graphical Design</a>
</li>
<li class="top-link"> <a href="#">Interior Design</a>
</li>
<li class="top-link"> <a class="a3" href="#">Arts / Illustrations</a>
</li>
<li class="top-link"> <a href="contact.html">Contact</a> </li>
</ul>
</nav>
发布于 2019-07-22 13:06:32
您也可以选择使用CSS flex进行布局,并将flex-grow: 2;
应用于那些需要更宽的元素。请找到下面的演示
/* the whole menu */
#menu {
text-align: center;
width: 100%;
margin: 0;
display: flex;
}
/* Horizontal list menu */
.top-link {
flex-grow: 1;
flex-basis: 0%;
display: inline-block;
flex-grow: 1;
position: relative;
font-size: 1.5rem;
font-weight: bolder;
padding: 1.2em 0;
}
.wider {
flex-grow: 2;
}
/*Style for menu links*/
.top-link a {
display: block;
/* links fill the block*/
color: var(--text-color);
line-height: 1rem;
text-align: center;
}
/*Hover state for top level links*/
.top-link:hover {
background: red;
color: rgb(255, 255, 255);
}
<nav>
<ul id="menu">
<li class="top-link"> <a href="about.html">About</a> </li>
<li class="top-link wider">
<a href="#">Graphical Design</a>
</li>
<li class="top-link"> <a href="#">Interior Design</a>
</li>
<li class="top-link"> <a class="a3" href="#">Arts / Illustration</a>
</li>
<li class="top-link"> <a href="contact.html">Contact</a> </li>
</ul>
</nav>
发布于 2019-07-22 13:55:12
试试这个:-
/* the whole menu */
#menu {
text-align: center;
width: 80%;
margin: auto;
}
/* Horizontal list menu */
.top-link {
display: inline-block;
float: left;
position: relative;
font-size: 1.5rem;
font-weight: bolder;
}
/*Style for menu links*/
.top-link a {
display: block; /* links fill the block*/
color: var(--text-color);
width: 100%;
padding: 1.2em 2.7em;
line-height: 1rem;
text-align: center;
}
/*Hover state for top level links*/
.top-link:hover a {
background: red;
color: rgb(255, 255, 255);
}
#menu li:nth-child(4) {
margin-right: 130px
}
https://stackoverflow.com/questions/57139248
复制相似问题