See the end of the clearfix hack

"display:flow-root" vs. "clearfix"

A new value of the display property that will enable containers to contain floats. Needs Chrome Canary or Firefox Nightlies .

In the following examples, the markup is as follow:

<div class="float"></div>  
<div class="container">
  <div class="float"></div>
  <p>Lorem Ipsum</p>
</div>

Note that all floats are styled with a margin of 20px.

.clearfix

In this example we use "clearfix" to cause the wrapper ( .container ) to contain the floated item.

Lorem Ipsum

2 things to notice:

display:flow-root

With flow-root our boxes behave very differently:

Lorem Ipsum

2 things to notice:

Why that?

flow-root creates a block-formatting context which—on top of containing floats—does a couple of other things:

Collapsing margin is a big deal

Let's see how siblings behave when styled with .clearfix

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

versus display:flow-root

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum