CSS Self Clearing Floats

October 15, 2008 11:39 by Alexey

We all remember good old “clearfix” (www.webtoolkit.info/css-clearfix.html) that we use to clear floats.

This is a new “lighter” version, based on the same principle.

.clearfix:after { content: ""; display: block; clear: both;}.clearfix { //display: inline-block;}

The major difference from the original clearfix is that we use blank content (“”) in “:after”, instead of “.” in the original one. That helps us to get rid of three extra lines of code, which purpose was to hide this dot:

visibility: hidden; line-height: 0; height: 0;

and to get rid of one more IE6 specific selector used for the same reason.

* html .clearfix { height: 1%;}

If you not too concerned about validity of your CSS you could leave the code as it is, else you can put .clearfix {//display:inline-block;} (the IE specific declaration) into separate IE Only CSS, or use the same trick, as per original clearfix – redefine “inline-block” to simply “block” for not IE, using:

html[xmlns] .clearfix { display: block;}

after IE’s “inline-block”.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: Technical
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts

Comments

Add comment


 

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

July 31. 2010 20:18

Calendar

July 2010
SuMoTuWeThFrSa
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567