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.

Nested floated div breaks wrapper!

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

No responses yet to Solution to nested DIV float problems

Why not give me your comments?

You can use these tags in your comment:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

See also:

CSS floats: container does not stretch to fit floated contents

Nested div float problems

Here’s a quick resolution to an almost ungooglable problem. ...

  • Originally published: 18 Jan 2006 in Technical

Am I a DIV or what?

Kelmscott by Bronwen Hodgkinson on csszengarden.com

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

IE in freefall

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

No bug

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

Stylised image of MOSS

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?

Photo

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.

RSS feeds