The Wayback Machine - https://web.archive.org/web/20090204220115/http://www.webreference.com:80/html/tutorial10/5.html


spacer

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

Boxing with CSS, Part II: No Margin For Error

Exploring the Box Ocean in Explorer Continued


Developer News
Open Source ECM Growing Up
Android's Second Act, G2 Rumors Heat Up
Eclipse Rolls Out PHP Development Tools 2.0

With no padding the code looks like this:

BODY {
  margin: 5mm;
}
DIV {
  margin: 5mm;
  border: 5mm solid green;
  background: cyan;
}
P {
  margin: 5mm;
  border: 5mm solid blue;
  background: magenta;
}

The words "beta testing" come to mind, as in the sentence "hasn't Microsoft heard of beta testing their browser's layout capabilities before they release it?" The above example can hardly be said to be a complicated one, but you and I both know it's not supposed to look like that. Space above the DIV is still less than it should be. There's no vertical margin above the first paragraph. There's some bottom padding on the second one (don't know where that came from) and... a negative bottom margin? Let's try increasing vertical margins and see what increases.

BODY {
  margin: 5mm;
}
DIV {
  margin: 5mm;
  border: 5mm solid green;
  background: cyan;
}
P {
  margin: 10mm 5mm;
  border: 5mm solid blue;
  background: magenta;
}

Well, it got the DIV top margin right this time. But that's probably because it's displaying the first paragraph's top margin outside the DIV. The inter-paragraph spacing is still correct, thank God, but that's about all that's changed. Let's see, what else can we try? I know, let's get rid of the borders too.

BODY { margin: 5mm; }
DIV {
  margin: 5mm;
  background: cyan;
}
P {
  margin: 10mm 5mm;
  background: magenta;
}

Well, the mysterious padding is gone. The rest remains more or less the same. Thumbs up to Microsoft for correctly implementing collapsing margins between sibling elements. Thumbs down for everything else concerning horizontal spacing.

This bug, which I have christened the "collapsing padding" bug, can be described as follows (stop me when this begins to sound too technical): Explorer will handle vertical spacing between elements with the same parent correctly. When you try to mess with the spacing between elements and their parents, however, don't expect anything to work.

The way around this bug is to try anything you can think of until you get it to work. Once again, if anyone has any more solid suggestions to make, feel free to let me know.

Front Page1234567

http://www.internet.com

Produced by Stephanos Piperoglou

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 >
Using Dojo for Client-Side Validation · Apache Basics, Visited · Introduction to AJAX Technologies
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
How to Restore an SSAS database using Windows PowerShell and SQL Server 2008 AMO · iWork '09 vs. Office 2008 vs. Google Docs · Online Video Ads: Affiliate, AdWords News, SEO Tips, Trends


All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/html/tutorial10/
Created: Dec 2, 1998
Revised: Jan 27, 1999

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