FireFox 4 水平 CSS 菜单中的填充错误
我在此页面有一个水平 CSS 菜单:
在 Chrome、Safari 和Internet Explorer 8 呈现完美。在 FireFox 4 中,每个
都稍微太窄,在最后两项之间留下了间隙。下面是 HTML 的一个简单示例:
<ul id="top-nav">
<li><a href="#">Menu Item 1</a></li>
<li><a href="#">Menu Item 1</a></li>
<li><a href="#">Menu Item 1</a></li>
<li class="last-item"><a href="#">Menu Item 1</a></li>
</ul>
和 CSS:
#top-nav {
position: relative;
}
#top-nav li {
float: left;
height: 46px;
line-height: 46px;
width: auto;
}
#top-nav li.last-item {
position: absolute;
top: 0;
right: 0;
}
#top-nav li a {
display: block;
padding: 0 38px;
}
我尝试在 body
标记上使用 -moz-box-sizing
CSS 属性,但无济于事。
感谢任何有想法的人。
更新
引起我注意的是,Windows 中的 FF 4 可以正确呈现此内容,但 IE 9 则不能。看来这是跨平台以及跨浏览器的不一致。这真的开始让我担心了。
另外,我在最后一个项目上使用了绝对定位,以确保它与 .wrapper div 保持齐平,从而使所有内容都居中。这样,浏览器渲染框宽度的不一致将永远无法通过将最后一个项目强制到第二行来“破坏”菜单,这比现在发生的情况更糟糕。
I have a horizontal CSS menu at this page:
In Chrome, Safari and Internet Explorer 8 it renders perfectly. In FireFox 4, each <li>
is just slightly too narrow, leaving a gap between the last two items.
Here's a quick example of the HTML:
<ul id="top-nav">
<li><a href="#">Menu Item 1</a></li>
<li><a href="#">Menu Item 1</a></li>
<li><a href="#">Menu Item 1</a></li>
<li class="last-item"><a href="#">Menu Item 1</a></li>
</ul>
And the CSS:
#top-nav {
position: relative;
}
#top-nav li {
float: left;
height: 46px;
line-height: 46px;
width: auto;
}
#top-nav li.last-item {
position: absolute;
top: 0;
right: 0;
}
#top-nav li a {
display: block;
padding: 0 38px;
}
I tried using the -moz-box-sizing
CSS attribute on the body
tag, but to no avail.
Thanks to anyone who has any ideas.
UPDATE
It was brought to my attention that FF 4 in Windows renders this appropriately, but IE 9 does not. It appears that this is a cross-platform as well as cross-browser inconsistency. It's really starting to concern me.
Also, I used absolute positioning on the last item to ensure that it stays flush right with the .wrapper div that keeps everything centered. That way, browser inconsistencies in rendering box-width would never be able to "break" the menu by forcing the last item to the second line, something way worse than what's going on now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你确定你做对了吗,伙计?我在 IE8、FF 4.0 和 FF 4.0.1 中看起来都是一样的,它们看起来是正确的。但是在 IE9 中,您描述的问题发生是因为最后两项(媒体和博客)之间存在间隙!
IE9
FF 4.0.1
之所以存在间隙,是因为您在最后一个列表项上设置了position:absolute,并且在top:0处设置了offset属性;右:0; - 如果你删除它,间隙就会消失。
Are you sure you got it right mate? I have looked the same in IE8, FF 4.0 and FF 4.0.1, and they look right. However in IE9, the problem you describe happens as there is a gap between the last two items, Media and Blog!
IE9
FF 4.0.1
The reason the gap is there because you have set position: absolute on the last list item with offset properties set at top: 0; right:0; - If you remove this, the gap will be gone.