CSS clearfix not working

user369246 picture user369246 · Jun 14, 2013 · Viewed 11.8k times · Source

This (http://jsfiddle.net/77RRA/1/) is working, while this (http://jsfiddle.net/77RRA/) is not.

Isn't clearfix supposed to substitute the line <div style="clear: both;"></div>?

Answer

Christoph picture Christoph · Jun 14, 2013

Isn't clearfix supposed to substitute the line <div style="clear: both;"></div>

Yes. The clearfix is there to avoid a non-semantic empty tag. However, for this to work you need to place it on the parent element. (Example)

In your case however, it does not address the problem that siblings will ignore the floated element. This is not the intend of clearfix, you simply add clear:right (or both as you will) on your #child sibling to restore the normal document flow.

your fixed Example