A web developer's blog. PHP, MySQL, CakePHP, Zend Framework, Wordpress, Code Igniter, Django, Python, CSS, Javascript, jQuery, Knockout.js, and other web development topics.

CSS: Float-clearing, getting containers to honor the height of floated elements inside of them

I accidentally stumbled on this article found at Agile AJAX. It talks about float-clearing, getting containers to honor the height of floated elements inside of them.

Here is a sample CSS code:

    /* float clearing for IE6 */
    * html #container,
    * html .classThatNeedsToBeCleared,
    * html div.anotherClassThatNeedsToBeCleared,
    * html #someDiv .someClass .yetAnotherClassThatNeedsToBeCleared{
      height: 1%;
      overflow: visible;
    }
 
    /* float clearing for IE7 */
    *+html #container,
    *+html .classThatNeedsToBeCleared,
    *+html div.anotherClassThatNeedsToBeCleared,
    *+html #someDiv .someClass .yetAnotherClassThatNeedsToBeCleared{
      min-height: 1%;
    }
 
    /* float clearing for everyone else */
    #container:after,
    .classThatNeedsToBeCleared:after,
    div.anotherClassThatNeedsToBeCleared:after,
    #someDiv .someClass .yetAnotherClassThatNeedsToBeCleared:after{
      clear: both;
      content: ".";
      display: block;
      height: 0;
      visibility: hidden;
    }
 
<div id="container">
    < div id="rail" style="float: left;">
    < div id="content" style="float: left;">
</div>

Click here for the entire post.

This entry was posted in General and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>