Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which clearfix method?

/* Clear Fix */

.clearfix:after {content: ".";display:block;height:0;clear:both;visibility:hidden;}
* html .clearfix {height:1%;}

or

.clearfix:after {content: ".";display:block;height:0;clear:both;visibility:hidden;}
* html .clearfix, *:first-child+html .clearfix {zoom:1;}

Which would work the best? I used first one by now and never had an issue.. Thanks.

like image 785
dzhi Avatar asked Jul 12 '10 09:07

dzhi


2 Answers

Most succinct technique is setting overflow:hidden for modern browsers:

overflow:hidden;
zoom:1;

If an element needs to flow out of the dimensions ( negative margins or positioning ) then clearfix:

#el:after { content:""; clear:both; display:block; visibility:hidden; }

For IE6 and below, you need to trigger hasLayout ( through a width, zoom:1, height, and other property/value combos ). Starting with IE7, overflow will clear the floats.

like image 105
meder omuraliev Avatar answered Sep 30 '22 18:09

meder omuraliev


The latter seems to be fine because it also considers IE6 (zoom:1;).

like image 22
Sarfraz Avatar answered Sep 30 '22 18:09

Sarfraz