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


spacer

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

home / experts / html / tutorials / 21 / 2

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

Floating over nothing

Now let's look at acme.css, the style sheet that is linked to this document.

/* 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 */
#main {
 margin-left: 40%;
}
#intro {
 width: 35%;
 float: left;
}
#footer {
 clear: left;
}

What we've done here is shrunk intro to 40% of the containing block's size (the containing block in this case is the DIV called body), and floated it to the left. This means that the elements following intro will be laid out as if it wasn't there, but their inline contents will be moved to the right so that they don't overlap with the float.

Now, if we give main a left margin of 40%, the elements in main will be displayed to the right of intro, creating what is effectively two columns.

You can view this example here. The result looks something like the following images on conforming browsers:

Multi-column layout using floats on Mozilla. Impeccable.
Multi-column layout using floats on Mozilla. Impeccable. [Full-sized image]

Multi-column layout using floats on Internet Explorer 5.0. Almost impeccable (can you spot the error?).
Multi-column layout using floats on Internet Explorer 5.0. Almost impeccable (can you spot the error?). [Full-sized image]

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/2.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.