我的 div 右侧有额外的空间。我试过 overflow:hidden 和 clear 但我无法摆脱它:(
这是我的HTML
<div id="menu">
<ul id="nav">
<li><a href="index.html">Home</a></li>
<li><a href="index.html">About</a></li>
<li><a href="index.html">Team</a></li>
<li><a href="index.html">Gallery</a></li>
<li><a href="index.html">Services</a></li>
<li><a href="index.html">Contact</a></li>
</ul>
</div>
这是CSS
#menu{
width: 800px;
height: auto;
border: none;
line-height:0;
margin-bottom: 10px;
}
/* Navigation */
#nav {
width: 100%;
overflow: hidden;
list-style: none;
display: inline;
}
#nav ul {
list-style: none;
overflow: hidden;
}
#nav ul li{
padding: none;
margin: none;
border: thin black dashed;
}
#nav li a {
background: #7b7b7b;
border-right: 1px solid #474747;
color: #fff;
display: block;
float: left;
font: 400 18px 'Iceland', Tahoma, Helvetica, Verdana, Arial, sans-serif;
padding: 10px;
text-align: center;
text-decoration: none;
text-transform: uppercase;
width: 14.1%;
-webkit-box-shadow: inset .5px .5px 15px .5px rgba(1, 1, 1, 0.5);
box-shadow: inset .5px .5px 15px .5px rgba(1, 1, 1, 0.5);
}
#nav li a:hover {
background: #bf0302;
}
nav li:last-child a {
border: none;
}
/* End of Navigation */
这是间距出错的地方。
(来源:picturetrail.com)
细黄色边框是菜单 div,红色边框是导航。
最佳答案
问题很简单,您在 NAV LI A 的右侧有一个 1px 的边框,因此您需要对此进行补偿。
所以添加这个:
margin-rigth:-1px;
最终 CSS:
#nav li a {
background: #7B7B7B;
border-right: 1px solid #474747;
color: white;
display: block;
float: left;
font: 400 18px 'Iceland', Tahoma, Helvetica, Verdana, Arial, sans-serif;
padding: 10px;
text-align: center;
text-decoration: none;
margin-right: -1px;
text-transform: uppercase;
width: 14.1%;
-webkit-box-shadow: inset .5px .5px 15px .5px rgba(1, 1, 1, 0.5);
box-shadow: inset .5px .5px 15px .5px rgba(1, 1, 1, 0.5);
}
Working DEMO | <强> Final Result
关于css - div右边的额外空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14231542/