force a div to contain floated child divs
You should use the clearfix method with pseudo-element :after because in your case, the clear isn't really applied after the children.
#main:after { content: "."; display: block; clear: both; visibility: hidden; line-height: 0; height: 0; }
EDIT 2020:
Since a while now, this simpler solution works just as fine:
#main::after { content: ""; display: table; clear: both;}
Also it’s now recommended to use ::after
instead of :after
to match other pseudo-elements.