A quick introduction to the CSS float & clear properties, how they work and what they do.
Float & clear
float
Inline-block will always have a little space between—where floated boxes can touch.
left
right
none
.column { float: left; width: 25%; }
<div class="columns"> <div class="col">Column 1</div> <div class="col">Column 2</div> </div>
.col { float: left; width: 50%; background-color: yellow; }
.columns { border: 3px solid red; } .col { float: left; width: 50%; background-color: yellow; }
.columns { border: 3px solid red; overflow: hidden; /* Simple clearfix */ }
<div class="columns clearfix"> <div class="col">Column 1</div> <div class="col">Column 2</div> </div>
/* Alternative clearfix */ .clearfix::after { content: " "; display: block; clear: both; }
You almost always have to clearfix the parent of floated elements.
overflow: hidden — Can clearfix parents, but also crops
overflow: hidden
.clearfix {…} — More reliable, more code
.clearfix {…}