Expand Div with Floats
1 min read

Expand Div with Floats

Problem

How do you expand a div to contain floats?
Elements like div’s grow to fit its contents, but when you use the float property on its children, the div will not expand.
The div will show a height of 0.

Solution to Contain a Float

Set the parent to overflow:auto.

<div style="overflow: auto;">
    <div style="float: left;">Div 1</div>
    <div style="float: left;">Div 2</div>        
</div>