【问题标题】:Extra space in the right of divdiv 右侧的额外空间
【发布时间】:2012-12-23 06:47:52
【问题描述】:

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

这就是间距出错的地方。
(来源:picturetrail.com

黄色的细边框是菜单 div,红色的边框是导航。

【问题讨论】:

  • width: 14.1%; 是罪魁祸首,加上特定的填充像素值意味着你永远不会得到“完美”。要修复它,找到正确的宽度像素值
  • #menu{width: 800px;} 是响应式设计吗?
  • 所以没有解决办法? @kmkaplan 是的,它是响应式的,我在媒体查询中将宽度设置为 100%,但问题仍然是它是否响应式。因为当网站处于全视图时,空白仍然存在。
  • @Andy 但是如果我把它改成 px 那么它就不适合不同的屏幕尺寸了。
  • 似乎您是响应式导航的新手,您应该检查一下:designshack.net/articles/css/code-a-responsive-navigation-menu

标签: css html responsive-design removing-whitespace


【解决方案1】:

问题很简单,您在 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

【讨论】:

  • 对我不起作用。它减少了导航宽度,然后增加了空白。
  • 我仍在寻找解决方案,给我时间 :D |这个在小屏幕上不起作用。
猜你喜欢
  • 1970-01-01
  • 2015-06-04
  • 2020-10-20
  • 2018-01-21
  • 1970-01-01
  • 2020-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多