Solution to nested DIV float problems

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?

See also:

CSS floats: container does not stretch to fit floated contents

Nested div float problems

This article was formerly titled “Alternative to the PIE clearfix hack” but has since been rewritten. Getting this problem? Example: Left Left Left Left Right Right Right Right <div style="background: red; padding: 2%; border: 1px solid #000;"> <div style="border: 1px solid #000000; ...

  • Originally published: 18 Jan 2006 in Technical

More IE woes: the curved corner DIV

In my current efforts to adhere to div-only layouts, it was expected that I would eventually get to a sticky point. I’m not used to hacking CSS, so progress for me ...

  • Originally published: 19 Jul 2005 in Technical

Am I a DIV or what?

Kelmscott by Bronwen Hodgkinson on csszengarden.com

Little by little, I’m being dragged into the 21st century (no coincidence that my boss’ name is Little) of CSS. Bronwen Hodgkinson’s beautiful “Kelmscott” design at csszengarden.com I’ve been doing CSS layouts ...

  • Originally published: 28 Jul 2005 in Technical

IE7 only: float bug on elements with italic, background properties

No bug

Setting font-style:italic in your CSS for elements in the vicinity of a floated element can actually trigger a float bug in Internet Explorer 7. This is only a problem, so far ...

  • 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 is that guy?

Photo of Mike Padgett

Hello you. I'm Mike Padgett and I work in the technology sector as an Information Designer.

I also enjoy travel, concerts, films and walking.

I'm based in Brussels, Belgium. My current favourite Belgian beer is St Feuillien Brune.

RSS feeds