Make sure to add a clearfix after floating the elements.
Apply the clearfix after each row.
CSS:
/**
* @info Clearfix: clear all floated elements
*/
.clearfix:after {
visibility:hidden;
display:block;
font-size:0;
content:" ";
clear:both;
height:0;
}
.clearfix {display:inline-table;}
/**
* @hack Display the Clearfix as a block element
* @hackfor Every browser except IE for Macintosh
*/
/* Hides from IE-mac \*/
* html .clearfix {height:1%;}
.clearfix {display:block;}
/* End hide from IE-mac */
HTML:
// Row
<div>
// Floated Div 1
<div></div>
// Floated Div 2
<div></div>
// ...
// ...
<div class="clearfix"></div>
</div>
// Row
<div>
// Floated Div 1
<div></div>
// Floated Div 2
<div></div>
// ...
// ...
<div class="clearfix"></div>
</div>
Consider using Normalize.css for improved CSS consistency across browsers: .
Normalize CSS resets styles and is well-maintained.