Forum Moderators: not2easy
[site details removed]
In Firefox the content body is spaced off the header area correctly ... 15px as set in my div padding
In IE it is about 30px or about double the correct height. This extra height only appears when the text is wrapped in a <p> tag and it only happens on the first and last occurance of the <p> tag within the div. It does not happen when span tags or other elements are used.
Is there something I shold do differently in my CSS?
Thank you for any help as I'm quite lost as to how IE is adding the extra space.
<No site specifics, thanks. See TOS #13 [WebmasterWorld.com]>
[edited by: SuzyUK at 9:31 pm (utc) on Sep. 11, 2006]
The P tag does have margins top and bottom by default. I think FF and IE can behave differently with floated elements in this respect - have you tried removing or setting the margin-top of the P tag?
Several folk on here have suggested setting the margins and padding for all elements to ZERO before you start and then set margins for each element as you go... must admit I have started doing this now as well for new projects... it does ensure they are then set the same in different browsers.
* {
margin:0;
padding:0;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
Or if you adhere to the strict standard (using no deprecated elements etc.) then the HTML4.01 Strict DOCTYPE is good:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
I just set "display: inline-block;" for the default <p> tag and that actually seems to help IE a little bit
Personally I don't see how this can have any effect... Ok, FF doesn't support inline-block (?) But neither should IE, on a <p> tag! "In IE6 and 7 it works only on elements that have a natural display of 'inline' (SPAN, A etc.)" (<p> is a block-level element)
If you are still having problems then paste the HTML/CSS and we can have a look...
Personally I don't see how this can have any effect... Ok, FF doesn't support inline-block (?) But neither should IE, on a <p> tag! "In IE6 and 7 it works only on elements that have a natural display of 'inline' (SPAN, A etc.)" (<p> is a block-level element)
FF doesn't support inline block it's true. IE supports inline-block on inline elements naturally, AND it can be made to do so on block elements in IE6/7 too which could perhaps account for the difference.
However the main thing is that inline-block; is a hasLayout trigger so its use is likely to cause things to be a bit different in IE.
@nwilcox, as you're suggesting the <p> elements is a cause here and only top and bottom I would think perhaps collapsing margins are actually in play here, IE also has another little foible whereby it's not very good at handling the collapsing of default margins so try adding your own explicit margins to elements:
p {margin 1em 0;}
to your CSS to see if that helps, also add temporary background colors to the elements that are affected header(?) & <p> so you can see exactly where the "gap" is.
Suzy
I tried "margin-top: 0;" again on my p tags and that fixes FF and Netscape ... but IE just flat simply ignores the 0 margin declaration. I colored the div and IE puts all this extra space aove the div so how can I control that if it isn't even in the div?
Is there a better way to force IE to behave correctly?
simple example to illustrate my question. Why does the P tag within the div affect the margin of the div? Shouldn't the div rest right underneath the div directly above it?
Shouldn't the div have extra padding around the p tag, not the margin outside the div
simple example to illustrate my question. Why does the P tag within the div affect the margin of the div? Shouldn't the div rest right underneath the div directly above it?
Your problem isn't a doctype issue, it's more likely a collapsing margins issue :)
Try putting 1px of padding on the
div in question, and if it pushes the p in its 'proper' place, then the problem is collapsing margins. So, like, what are collapsing margins?
Let's say you have a parent object which has a margin of 5px to its top edge, but no padding to that top edge. We're going to put a light green background on it just to see where it starts and ends.
Then we're going to put lots of
ps within that parent object, because that's what we do. Those
ps have a margin of 10px on them - so why does the first one sit flush against the top of the parent object (and its background colour?) And why is the margin on the top of the parent object now 10px? Simply put: