I came across the following code on the Internet.It works but I am not getting the jist of it that is how it is working? All div boxes get inside the container div when a dummy div with clear both property is added at the last otherwise they stay outside the container.Another thing which I got myself is that when clear was set to left it still worked ok.
HTML
<div id="main_container">
<p>Some content.</p>
<div class="floated_box"></div>
<div class="floated_box"></div>
<div class="floated_box"></div>
<div class="floated_box"></div>
<div class="floated_box"></div>
<div style="clear: both;"></div>
</div>
CSS
#main_container {
width: 400px;
margin: 20px auto;
border: 2px solid #cccccc;
padding: 5px;
}
.floated_box {
float: left;
width: 100px;
height: 100px;
border: 1px solid #990000;
margin: 10px;
}