Solution to nested DIV float problems
— A CSS hack for nested divs that break out of their container.”
This item is now out of date. See the updated version.
I recently discovered a CSS hack that has come in very handy indeed since.
The problem arises in both Firefox and IE (though the solution is different for each) when we try to wrap a div around one or more divs with float.

You want your wrapper to stretch vertically with your contained divs, but instead, you find that your wrapper gets behind when your floated content divs go stretching off down the viewport and beyond.
The development community is all but silent on this issue, though I would think it’s a common enough problem to have encountered.
I tried and tested an IE solution, but it was thanks to Big John and Holly at positioniseverything that the NS / Firefox side of things could be cleared up. The full article with the whys and wherefores is here, and the code we need is as follows:
.clearfix:after {content: "."; display: block; height: 0; clear: both; visibility: hidden;}
.clearfix {display: inline-table;}
/* Hides from IE-mac \*/
* html .clearfix {height: 1%;}
.clearfix {display: block;}
/* End hide from IE-mac */
Now we get the result we want!
Comments
One response so far to Solution to nested DIV float problems
Why not give me your comments?
See also:
CSS floats: container does not stretch to fit floated contents
Here’s a quick resolution to an almost ungooglable problem.
- Originally published: 18 Jan 2006 in Technical
More IE woes: the curved corner DIV
Rendering CSS rounded corners is still surprisingly difficult thanks to inconsistently-applied browser standards.
- Originally published: 19 Jul 2005 in Technical
Am I a DIV or what?
Kicking out the tables means having to revise a lot of old habits.
- Originally published: 28 Jul 2005 in Technical
IE7 only: float bug on elements with italic, background properties
What do you get if you cross a float and an italic in Internet Explorer?
- Originally published: 13 Jul 2009 in Technical
Blog styles
Briam asked on the forum for the blog software that runs MikePadgett.com about template styles. I had written a brief article before MikePadgett.com was so kindly hacked about the work I’d
- Originally published: 19 Mar 2006 in The eponymous website
Who you gonna call?
Hello you, I'm Mike Padgett. I'm not a Princeton curator, Knoxville mayoral candidate, Kentuckian pastor or Arizona journalist, I just share the same name. In fact, I am a consultant working in user experience and information design.
I also enjoy travel, concerts, films and walking.
I'm originally from Yorkshire, England but nowadays I live in Belgium. My current favourite Belgian beer is Black Albert.
Shameless self-promotion
Over a year in the making, Dopeology.org is my latest personal project: a topology of doping in thirty years of European pro road cycling.
I collected information from thousands of sources, then I modelled and published it via a lightweight user interface.




October 27th, 2010 at 7:07
[...] simple. No way. Anyway, borrowed this image from http://www.mikepadgett.com. The problem is [...]