哪种clearfix方法?
/* 清除修复 */
.clearfix:after {content: ".";display:block;height:0;clear:both;visibility:hidden;}
* html .clearfix {height:1%;}
或
.clearfix:after {content: ".";display:block;height:0;clear:both;visibility:hidden;}
* html .clearfix, *:first-child+html .clearfix {zoom:1;}
哪个效果最好? 我现在用的是第一个,从来没有遇到过问题。 谢谢。
/* Clear Fix */
.clearfix:after {content: ".";display:block;height:0;clear:both;visibility:hidden;}
* html .clearfix {height:1%;}
or
.clearfix:after {content: ".";display:block;height:0;clear:both;visibility:hidden;}
* html .clearfix, *:first-child+html .clearfix {zoom:1;}
Which would work the best?
I used first one by now and never had an issue..
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简洁的技术是为现代浏览器设置溢出:隐藏:
如果元素需要流出尺寸(负边距或定位),则clearfix:
对于IE6及以下版本,您需要触发hasLayout(通过宽度,缩放:1,高度和其他属性/值组合)。从 IE7 开始,溢出将清除浮动。
Most succinct technique is setting overflow:hidden for modern browsers:
If an element needs to flow out of the dimensions ( negative margins or positioning ) then clearfix:
For IE6 and below, you need to trigger hasLayout ( through a width, zoom:1, height, and other property/value combos ). Starting with IE7, overflow will clear the floats.
后者似乎没问题,因为它也考虑了 IE6 (
zoom:1;
)。The latter seems to be fine because it also considers IE6 (
zoom:1;
).这一直对我有用。与你的非常相似
This has always worked for me. Very similar to yours