<div> is compressed when a float is applied to its subitems
I am trying to create an element container in the main container of my website. To create a container of elements in a row, I applied to them float:left;. But when I added to them float, the main container shrinks! I tried applying clear:bothto the main container, but nothing has changed.
CSS:
#main_container
{
clear:both;
margin-top:20px;
padding:20px 10px 30px 15px;
background:#ccc;
}
.element_container
{
float:left;
width:238px;
height:300px;
border:1px solid #000;
}
HTML:
<div id="main_container">
<div class="element_container"></div>
<div class="element_container"></div>
<div class="element_container"></div>
</div>

+5
4 answers