I need help understanding this better. Why does the margin on the h2 tag push the parent container (hsaBottom) down? I would assume that the h2 tag would be pushed down inside the parent, but instead it pushed the entire container down. This doesn't happen in IE 6 and IE 7, but does happen in Firefox 3, Opera 9.5, Safari 3 all on Windows. Any ideas? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <head> <title>Child Margin Test</title> <style type="text/css"> #hsaBottom{ width: 400px; height: 100px; background: #cccccc; margin:10px; } #hsaBottom h2{ margin:100px 0 0 0; } </style> </head> <body> <div id="hsaBottom"> <h2>What is the deal?</h2> </div> </body></html> Code (markup):
You must either float the #hsaBottom, or give it absolute position, or change margin to padding in h2 style.
I'm not positive, but I suspect it has something to do with the famous uncollapsing margins: http://complexspiral.com/publications/uncollapsing-margins/
Quite right. IE acts differently because it does not properly collapse margins where the parent has hasLayout. cheers, gary
Hi... try this css <style type="text/css"> #hsaBottom{ width: 400px; height: 100px; background: #cccccc; margin:10px; } #hsaBottom h2{ padding:78px 0px 0px 0px; margin:0px; } </style>
The fact this doesn't work in any of the modern browsers, but did in IE, speaks volumes on IEs incompetence as a web browser. Never, ever use any version of IE as a reference for what works. Always, always use any other browser as your initial test. Even IE8 is 10 years behind web standards and wrong in much of its implementation.
I agree that IE doesn't follow web standards, but if a site doesn't look good in IE, it isn't really worth putting out on the web.