当前清除浮动的最佳解决方案是什么,例如“
”?

发布于 2024-10-01 01:54:32 字数 343 浏览 4 评论 0原文

我曾经用来

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

仅冇旳回忆 2024-10-08 01:54:32

根据情况,我主要使用溢出或浮动父元素。没有最好的解决方案。

Depending on the situation, I mostly use overflow or float the parent element. There is no best solution.

等你爱我 2024-10-08 01:54:32

我实际上喜欢这里解释的方法: 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.

删除→记忆 2024-10-08 01:54:32

我了解到
内容:“”;
显示:表格;
明确:两者;
适用于 IE 8+ 之后的所有浏览器

I have learned that
content: "";
display: table;
clear: both;
work with all browsers after IE 8+

晒暮凉 2024-10-08 01:54:32

我喜欢clearfix。也读一下这个(直到现在我才知道):您对 Clearfix 的了解都是错误的

I like clearfix. Read this too (which I didn't know about until just now): Everything you Know about Clearfix is Wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文