clearfix after floating elements with pseudo element

℡╲_俬逩灬. 提交于 2019-12-12 02:04:08

问题


I have three floating div-containers but the clear-fix-solutions I found on other websites don't work. I think I am doing something wrong but don't know what.

How do I write a correct clearfix?

Here is a fiddle:

http://jsfiddle.net/h23A5/

HTML:

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

And CSS:

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

回答1:


A "clearfix" on an element applies to floats inside that element, and is designed to prevent the element from "collapsing" due to the floats.

You don't need a clearfix here. You're simply looking to clear the floats normally. A simple clear: left or clear: both on the element following the floats is enough.



来源:https://stackoverflow.com/questions/25039447/clearfix-after-floating-elements-with-pseudo-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!