Sunday, March 18, 2007

Easy Clearing - How to clear floats in an enclosing container, the easy way.

It's basically saying that they don't like the current way of doing the following to clear a float in a container:


<div> <!-- float container -->
<div style="float:left; width:30%;"><p>Some content</p></div>
<p>Text not inside the float</p>
<div style="clear:both;"></div>
</div>


and instead they recommend you put a ".clearfix" class in each float you want to clear, and put the following in your CSS file.


.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}


Well, I think this is pretty ugly, and as well, you still have to put a ".clearfix" attribute in the container you want to fix, so I will still be doing it the old way, myself.