Ramblings

August 12, 2010

Making a clean float clear

Filed under: Uncategorized — Tags: , — michaelangela @ 4:33 pm

This is a note for reference in case I run into some funkiness that looks like this might address. Very nice and concise.

Breaking Floats Without Hacks

When you want to clear all floats across the entire width of the page or a div, this single line of CSS code just won’t cut it when using: <div class=”clear”></div>.

  1. clear: both;

Instead, we’re going to use four lines.

  1. width: 100%;
  2. height: 1px;
  3. margin: 0 0 -1px;
  4. clear: both;

Alright, let’s break this down. First of all, the major problem with clearing correctly in all browsers lies mainly in a few of Internet Explorer’s quirks. Both width: 100%; and height: 1px; force the browser into accepting that there is a div there. The margin: 0 0 -1px; negates the 1 pixel space that height introduced; this is the only property that is not required. Natually, clear: both; is the special ingredient to make all of this work.

 

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: