Click to See Complete Forum and Search --> : IE & Floated DIVS margin problem


ripper2020
06-02-2008, 03:11 PM
Hello all, I have been reading alot about IE's rendering problems with margins etc and "haslayout".

My problem is I have a floated div and inside that div, the first <p> tag does not have any top margin in ie7, but it does in firefox. I have read about using overflow etc to force margins but I can not get it to work. To simplify things, i will show you what code i want to work. Any suggestions would be greatly appreciated!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<div style="float:left; width:75%; border:solid 1px #000000; ">
<p style="font-size:1em;border:solid 1px #000000; width:100%;">TEST</p>
<h1 style="font-size:1em;border:solid 1px #000000;">TEST</h1>
</div>
</body>
</html>

So what i need is there to be the same margin? (space) from the top of the page to the first p tag in ie and firefox. IE has none, firefox does.

Centauri
06-02-2008, 06:44 PM
Different browsers use different default margins for elements, including <p>. If you want the same margins in each browsers, specify them rather than rely on defaults p {
margin: 1em 0;
}

ripper2020
06-02-2008, 06:50 PM
Different browsers use different default margins for elements, including <p>. If you want the same margins in each browsers, specify them rather than rely on defaults p {
margin: 1em 0;
}
Thanks, and although thats true, the problem is only with the first child element of the floated div. So the next <p> tag would have proper spacing above and below it. Why is it only the first one?

Centauri
06-02-2008, 06:57 PM
I am guessing that IE does not apply a top margin to <p>s by default, only a bottom one - don't have the time right now to check that out though.