Hello,

I have a question about collapsing margins. I realise that the margins
of relatively and absolutely positioned elements are not supposed to
collapse, but I've come across an example that appears to break this
rule. I'd be grateful if someone could clarify what is going on.

I have a simple html document with the following elements /
positionings:

body (relative)
division #div_content (relative)
division #div_alpha (absolute; top: 0;)
division #div_omega (relative; top: 0;)

The division #div_content is a wrapper for all other content. The other
two divisions, #div_alpha and #div_omega, are siblings which each hold a
single h1 element. Each h1 element is styled to have a top margin.

My issue is that, in all major browsers, the margin of the h1 of
#div_omega collapses with the margin of body, even though #div_omega has
been relatively positioned. Furthermore, adding padding to the body does
not seem to fix the problem.

A sample html document with inline style sheet is attached.

I'd be grateful for any guidance on this. Thank you.

Regards,

Grant Bailey
...

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<style type="text/css">
<!--
* {margin: 0; padding: 0;}
body {position: relative; margin: 5em; height: 400px; outline: black
thin solid;}
h1 {margin-top: 1em; outline: black thin solid;}
#div_content {position: relative; outline: black thin solid;}
#div_alpha {position: absolute; top: 0; left: 0; outline: black thin
solid;}
#div_omega {position: relative; top: 0; left: 50%; outline: black thin
solid;}
-->
</style>
</head>
<body>
<div id="div_content">
<div id="div_alpha">
 <h1>I am the alpha</h1>
</div>

<div id="div_omega">
 <h1>I am the omega</h1>
</div>
</div>
</body>
</html>  



*******************************************************************
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [email protected]
*******************************************************************

Reply via email to