我正在处理一个具有水平居中导航栏的网站。该导航栏的两端必须有圆角以及悬停效果。所有这些都基本上可以实现,但问题是导航栏的悬停超出了实际大小。此外,每个元素之间存在轻微的白色空间。如jsfiddle所示,它看起来不太对。另一个重要的注意事项是,导航栏必须与Bootstrap和响应功能一起使用。这意味着不能使用绝对定位或浮动等。下面我还附上了HTML和CSS代码。
<div class="navTopRight">
<ul class="naviTop">
<li class="first"><a href="index.html">Home</a></li>
<li><a href="#scrollToBot">Item1</a></li>
<li><a href="Item2.html">Item2</a></li>
<li><a href="Item3.html">Item3</a></li>
<li class="last"><a href="Item4.html">Item4</a></li>
</ul>
</div>
CSS
.navTopRight{
text-align:center;
list-style-type: none;
margin-top: 30px;
padding: 0;
}
ul.naviTop li {
border:1px solid black;
display: inline;
overflow:hidden;
background-color:#003340;
}
.navTopRight li:last-child {
border-right: none;
}
.navTopRight li a{
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
display: inline;
}
ul.naviTop li a:hover {
background-color:#0099bf;
}
li.first{
border-top-left-radius:5px;
border-bottom-left-radius:5px;
}
li.last{
border-top-right-radius:5px;
border-bottom-right-radius:5px;
}