css - div右边的额外空间

标签 css html responsive-design removing-whitespace

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

这是间距出错的地方。 Picture
(来源: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/

相关文章:

CSS 响应式 img 按宽度和高度缩小

html - 坚持 HTML block 的响应高度

html - 嵌套导航列表中的 CSS3 列大小和对齐问题

html - HTM 文档无法在 Word 中打开

php - 插入表格单元格的文本,可点击的 URL 链接?

html - HTML 中的值与占位符属性

javascript - 使用 JavaScript 和 ajax 在给定文件夹中搜索图像?

html - 如何在另一个下方创建两个响应单元格?

html - 可收缩的 div 或单元格表

css - 具有固定边距的响应式/流体 4 列