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!
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
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
More IE woes: the curved corner DIV
Rendering CSS rounded corners is still surprisingly difficult thanks to inconsistent applied browser standards. ...
- Originally published: 19 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
Accessibility may affect feasibility of Sharepoint intranet
Microsoft’s Office Sharepoint Server 2007 packs some cosmetic improvements to accessibility, but considerable development will be needed to resolve out-of-the-box problems. ...
- Originally published: 22 Oct 2007 in Technical
Who you gonna call?
Hello you, I'm Mike Padgett. I'm not the Princeton curator, the US senatorial candidate, the Kentuckian pastor or the journalist from Arizona. In fact, I work as a consultant 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 Brussels, Belgium. My current favourite Belgian beer is Ellezelloise Hercule.



Comments
No responses yet to Solution to nested DIV float problems
Why not give me your comments?