html - 带有伪元素的 float 元素后的clearfix

标签 html css clearfix

我有三个 float 的 div 容器,但我在其他网站上找到的 clear-fix-solutions 不起作用。我想我做错了什么,但不知道是什么。

如何编写正确的 clearfix

这是一个 fiddle :

http://jsfiddle.net/h23A5/

HTML:

<div class="box"></div> 
<div class="box"></div> 
<div class="box nomargin clearfix"></div>

和CSS:

.clearfix:after {
    visibility: hidden;
    display: block;
    content: "";
    clear: both;
    height: 0;
}
* html .clearfix             { zoom: 1; } /* IE6 */
*:first-child+html .clearfix { zoom: 1; } /* IE7 */

最佳答案

元素上的“clearfix”适用于该元素内的 float ,旨在防止元素因 float 而“折叠”。

这里你不需要 clearfix。您只是想正常清除 float 。一个简单的 clear: leftclear: both 就足够了。

关于html - 带有伪元素的 float 元素后的clearfix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25039447/

相关文章:

html - Internet Explorer 的最小 CSS (7,8,9)

javascript - 如何设置导航栏的事件状态?

css - 居中的 div 底部边距溢出父级

c# - MVC Razor 隐藏输入和传递值

html - 在保持切换菜单(汉堡包)的同时更改导航栏背景颜色

css - 如何在 webkit、opera 浏览器的 f/ckeditor 中禁用所选图像的蒙版?

css - Bootstrap - 表在列中重叠

javascript - 调整 nivo slider 设置不起作用

css - 为什么溢出:hidden expands parent element (containing floated child elements)?

html - 如何正确清除这些 float 的 div?