div右侧的额外空间

时间:2013-01-09 09:01:24

标签: css html5 html responsive-design removing-whitespace

我的div右侧有额外的空间。我试过溢出:隐藏和清除,但我无法摆脱它:(

这是我的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 */

这是间距出错的地方。 Picture 薄黄色边框是菜单div,红色边框是导航。

1 个答案:

答案 0 :(得分:2)

问题很简单,你正在使用1px的边界来达到NAV LI A的范围,所以你需要补偿这一点。

所以加上这个:

余量-分辩:-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