Jump to content

Clearing the new and not the old fashion way


TheFilmGod

Recommended Posts

The article on position is everything is a little old. It works better than a clearing div but you still need to add a class of "clearfix" to html elements you want to self-clear. Instead you can do it all in the stylesheet (and forget IE5/Mac):

 

/*Clearing for Modern Browsers */
#myelement:after,
#anotherelem:after {
  clear:both;
  content:".";
  display:block;
  height:0;
  font-size:0;
  line-height:0;
  visibility:hidden;
}

/*Clearing for IE6 only*/
* html #myelement,
* html #anotherelem {
  height:1%;
}

/*Clearing for IE7 only*/
*+html #myelement,
*+html #anotherelem {
  min-height:1px;
}

 

I like to put the IE declarations into IE stylesheet to avoid the selector "hacks". The {min-height:1px} for IE7 doesn't actually have any negative effect on other browsers, so you could put it in your normal stylesheet...just depends on whether you prefer to have the clearing css all in the same place and obvious what it is doing!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.