Float clearing with overflow

Creative Technology

Without a doubt, the biggest impact my CSS world is the float clearing powers of overflow. After struggling so many times with solutions to avoid mark-up based clearing (i.e. a span with a clear class), and admittedly finding some success with the Clearfix solution. I found this article by Sitepoint. Devastatingly simple, easy to implement, and I have followed this, in most cases, ever since.

Overflow

The solution however isn’t without it’s own problems – scrollbars often appear on the wrapping DIVs. Particularly if you’re tightly wrapping a selection of links. I.e. a menu bar. A fix came about when a work compadré, Sam Loomes, recently made a brilliantly simple observation, that maybe the fix would work by setting overflow to hidden. God damn, it worked, scrollbars are banished and the clearing still occurs!

So here it is, CSS overflow fix in all it’s, um, glory. With no semantic or layout implications. Enjoy.

.wrapper {
    overflow: hidden;
}

Permalink / Leave comment (1)

Comments

Author Stephan
Posted April 1, 2010

Note that this method isn’t the solution to everything. For example if the element with overflow: hidden contains some dynamic, absolutely positioned content then the stuff that’s normally supposed to appear outside of the box is just cut off, or hidden, respectively. This also happens with overflow: auto.

Secondly, for this to work in IE, the respective element needs “layout” (refer to http://www.satzansatz.de/cssd/onhavinglayout.html).

So always use with caution.

Leave a comment