当前清除浮动的最佳解决方案是什么,例如“”?
我曾经用来
<div style="clear: both"></div>
清除浮动...并且见过它的情况
<div style="clear: both; height: 1px; line-height: 1px"></div>
,也见过clearfix,有些带有隐藏的 .
并使其与背景颜色相同。现在Compass和Blueprint也有一个+clearfix
。既然我们可能不需要支持 IE 6,那么当前清除浮动的最佳方法是什么?
I have used
<div style="clear: both"></div>
to clear the floats... and have seen cases where it is
<div style="clear: both; height: 1px; line-height: 1px"></div>
and have seen clearfix, and some with a hidden .
and make it the same color as the background. Now Compass and Blueprint also have a +clearfix
. What is the current best way to clear floats, now that probably we don't need to support IE 6?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据情况,我主要使用溢出或浮动父元素。没有最好的解决方案。
Depending on the situation, I mostly use overflow or float the parent element. There is no best solution.
我实际上喜欢这里解释的方法: http://www.quirksmode.org/css/clearing.html 。它避免了向 html 添加额外的元素。
I actually like the method explained here: http://www.quirksmode.org/css/clearing.html. It get's away from adding an extra element to the html.
我了解到
内容:“”;
显示:表格;
明确:两者;
适用于 IE 8+ 之后的所有浏览器
I have learned that
content: "";
display: table;
clear: both;
work with all browsers after IE 8+
我喜欢clearfix。也读一下这个(直到现在我才知道):您对 Clearfix 的了解都是错误的。
I like clearfix. Read this too (which I didn't know about until just now): Everything you Know about Clearfix is Wrong.