Clearfix Method

Clearfix Method

When a floated element is within a container box, that element does not automatically force the container’s height adjust to the floated element. When an element is floated, its parent no longer contains it because the float is removed from the flow. You can use 2 methods to fix clearfix & overflow: hidden

Example:

<div class="wrapper">
     <div style="float:left;">Left</div>
     <div style="float:right;">Right</div>
</div>

In this case you can add wrapper style 'overflow:hidden' or  add 'clearfix' class

 

.clearfix:after {
    visibility: hidden;
    display: block;
    font-size: 0;
    content: " ";
    clear: both;
    height: 0;
}

.clearfix { display: inline-table; }

/* Hides from IE-mac */
*html .clearfix { height: 1%; }
.clearfix { display: block; }
/* End hide from IE-mac */

IE hacks
* html .clearfix             { zoom: 1; } /* IE6 */
*:first-child+html .clearfix { zoom: 1; } /* IE7 */