overflow:auto

midrange

Senior Member
Joined
Apr 8, 2009
Messages
727
Anyone got this to work on a parent, cross-browser, as a way to avoid using an extra clearing div after floated elements? Read a lot about it, but I always end up having to use the clearing div.
 

CrazyBob

Senior Member
Joined
Jun 29, 2005
Messages
541
Yeah, use it all the time ...you just have to declare a width (I think height works too) on the wrapping div. Can also use overflow:hidden.

Code:
<div style="width:100%; overflow:hidden;">
  <div style="float:left; width:50%">
    float 1
  </div>
  <div style="float:left; width:50%">
    float 2
  </div>
</div>
 
Last edited:

CrazyBob

Senior Member
Joined
Jun 29, 2005
Messages
541
np ;)

Clearing div's are so 2005 (or so :p)

I always try to use the best methods of clearing first, in this order:

1) a simple clear:both on a sibling element that appears directly after the floats (obviously only if such an element exists).
2) this overflow:hidden/auto one
3) the clearfix class (http://www.webtoolkit.info/css-clearfix.html)
.
.
.
.
.
.
4) if none of those are working out, only then do I resort to an extra clear div - only ever ran into this issue once, and then it was just for IE where i used conditionals.
 
Top