I am puzzled why the code below renders correctly without any issues until I add a doctype declaration:
<body style="margin:0; padding:0; background-color:#eeeeee"></body>
<div id="HeaderContainer" style="background-color:#eeeeee; color:Black; border-bottom:1px solid #cccccc; height:60px; margin:0px"></div>
<div style="width:100%; background-color:White; margin:0px; padding:0px">
<div style="margin:30px; width:840px; margin:10px auto; margin-top:50px; background-color:#cc0000;">
text
</div>
</div>
</div>
</body>
My intention is to have a header (a grey bar) with a dark grey border at the bottom. Underneath it, there should be content within a large div that takes up 100% of the width and has a white background. The above code appears fine initially, but as soon as I include the following line at the beginning:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The innermost div's margin changes from white to grey, resulting in a visually incorrect layout.
Can someone clarify this unexpected behavior? This issue was observed in IE8, but it persists in Chrome as well.
Image description: