The Wayback Machine - https://web.archive.org/web/20081211125834/http://www.webreference.com:80/html/tutorial21/4.html


spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / html / tutorials / 21 / 4

index12345

Tutorial 21: CSS Floats, Part II

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Floats in practice

Seeing this problem with floats and columns, the only use of floats today is to create floats with the default appearance: a block of text up against the side of the viewport with text flowing around. Although not as neat as multiple columns, this effect is useful and not something you can do with HTML alone. So, we can change the style sheet we used above to the following:

/* Looks */
BODY {
 background-color: #FFFFFF;
 color: #000000;
}
A:link { color: #8B7CFF; }
A:visited { color: #483ACE; }
A:active { color: #CC0000; }
H1 {
 font: bold italic large Arial, Helvetica, sans-serif;
}
H2 {
 font: italic large Arial, Helvetica, sans-serif;
}
#intro {
 border: medium solid #ACA250;
}
#header P {
 border: medium solid #ACA250;
 text-align: center;
}
#footer P {
 font-size: smaller;
 text-align: right;
}

/* Layout */
#intro {
 float: right;
 width: 35%;
}
#footer {
 clear: right;
}

This puts our little intro on the upper right hand corner of the page. The good thing about this simple technique is that it works with all CSS-supporting browsers, with one little niggle. Take a look at a screenshot of this page on Internet Explorer 4.0:

A right float in Internet Explorer 4.0.
A right float in Internet Explorer 4.0. [Full-sized image]

As you can see, IE4 right-aligns the text in the float. This is a bug in IE4, but is easy to work around: Just add an explicit text-align property for the float in your style sheet, which will now look like this:

/* Looks */
BODY {
 background-color: #FFFFFF;
 color: #000000;
}
A:link { color: #8B7CFF; }
A:visited { color: #483ACE; }
A:active { color: #CC0000; }
H1 {
 font: bold italic large Arial, Helvetica, sans-serif;
}
H2 {
 font: italic large Arial, Helvetica, sans-serif;
}
#intro {
 border: medium solid #ACA250;
 text-align: left;
}
#header P {
 border: medium solid #ACA250;
 text-align: center;
}
#footer P {
 font-size: smaller;
 text-align: right;
}

/* Layout */
#intro {
 float: right;
 width: 35%;
}
#footer {
 clear: right;
}

This should give you a nice float that works with all browsers, has no problems with viewport resizing, and falls back gracefully to a default layout on non-CSS browsers.

index12345

http://www.internet.com/

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Copyright 2008 Jupitermedia Corporation All Rights Reserved.

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: qooxdoo and SproutCore · Getting Started with ASP.NET 3.5 · Administering MySQL Databases on the Web Using PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
OCZ Unveils the CrossOver USB 2.0 Flash Drive · Pick the Winners: Excellence in Technology Awards · Online Ad Network PremiumChannels Nets Niche Viewers

Legal Notices.

URL: http://www.webreference.com/html/tutorial21/4.html

Produced by Stephanos Piperoglou
Created: April 05, 2000
Revised: April 5, 2000

Morty Proxy This is a proxified and sanitized view of the page, visit original site.