CSS Crib sheet #2 - Clearing Floats | December 18, 2003
When floating elements it's fairly common to add an element to your document who's sole purpose is to clear the preceding float.
In a site I'm currently building, our developer added a <br class="clear" /> element to do this job. It worked fine in Safari but in IE/Win it would only clear the preceding float, not all the floats.
I thought the problem was down to the fact that the <br /> was inline, so a changed it to block. However it still didn't work in IE. It would have been nicer semantically to have been able to use a <br />, however in the end I resorted to using a block level element. We actually used a <p> containing a but normally I'd do this:
.clear {
clear: both;
height: 0;
}
<div class="clear"><!-- --></div>
Which has the added benefit of leaving no vertical space. something which can be quite important in certain layouts.
Posted at December 18, 2003 11:26 AM
Oleg Bezuglov said on December 18, 2003 12:02 PM
it’s simple and fine! thank you for thinking bout another “brick”