...

View Full Version : 'p' in div behaves strangely in IE8?



mehere8
07-21-2011, 06:23 AM
the red part below, 'p' tag, seems to have a bottom margin stick out of the containing 'div', pushing down the following footer -- copyright part. If 'p' tag is erased, it will show the position of footer correctly. This is what happens in IE8. However, IE7 and FF4 does behave as expected.

if the 'p' comes at the bottom of the 'div', I know that there is collapsing margin issue, resulting a bottom margin stuck out. But 'p' just lies at the start of the div which also has a min-height, 'p' should stretch its margin out of the div. is this a bug in IE8?

any help is 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>
<style type="text/css">
body {
margin: 0;
padding: 0;
background-color: #FC0;
}
#wrapper {
padding: 0;
width: 900px;
margin: 0 auto;
background-color: #FFF;
min-height: 300px;
}
#footer {
color: #FFFFFF;
text-align: center;
padding: 10px 0;
}
</style>
</head>

<body>
<div id="wrapper">
<img src="" width="900" height="200" />
<div id="center">
<p>aaa</p>
</div>
</div>
<div id="footer">Copyright 2005-2011 HHHHHHHHHHH</div>
</body>
</html>


also the red part can be replaced with <div style="margin-bottom:10px">aaa</div>. You will know what I mean by saying the margin bottom of 'p'

alykins
07-21-2011, 03:23 PM
insert *{margin:0px; padding:0px;} as first line in CSS. Clears problem

mehere8
07-22-2011, 03:45 PM
insert *{margin:0px; padding:0px;} as first line in CSS. Clears problem

ah i didn't mean to clear the margin bottom of 'p'
i just want to reserve that bottom margin.

To make it clear, replace 'p' with this part <div style="margin-bottom:10px">aaa</div>

so how to solve the problem? Is it the bug in IE8?

mehere8
07-23-2011, 04:35 PM
Anyone can help?

Sammy12
07-24-2011, 08:30 AM
all tags have default margins and paddings. alykins is right

* { margin: 0; padding: 0; }

try explaining the problem you are having better. I honestly cannot understand what it is your saying. The code you provided really didn't help either.

All I can say is that if you don't reset the default margins and paddings you will have a margin to the bottom by default of the <p> tag.

http://i1114.photobucket.com/albums/k535/auroralight1/Untitled-27.png

if you look to the right of your screen, you will see some margin-start type of stuff. These are default margins and paddings that I would recommend resetting

mehere8
07-29-2011, 10:06 AM
ok let's just remove those margins.

then


<!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>
<style type="text/css">
body {
margin: 0;
padding: 0;
background-color: #FC0;
}
#wrapper {
padding: 0;
width: 900px;
margin: 0 auto;
background-color: #FFF;
min-height: 300px;
}
#footer {
color: #FFFFFF;
text-align: center;
padding: 10px 0;
}
</style>
</head>

<body>
<div id="wrapper">
<img src="" width="900" height="200" />
<div id="center">
<div style="margin-bottom:10px">aaa</div>
</div>
</div>
<div id="footer">Copyright 2005-2011 HHHHHHHHHHH</div>
</body>
</html>


if you remove the style from the red part, you will see the footer shift upwards in IE8.
But you can see the div in red is too short to expand the outer div(center), let alone div(wrapper).
Do the same in IE7, FF. You will see no change after the style is removed.

Is it clear? So is it a bug in IE8?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum