views:

1645

answers:

2

In ie6 and ie7, the margin-bottom from the p is being applied to both the p AND the div just below it.

In other words, this code will apply a margin-bottom of 20px to both the p and the div in ie6 and ie7. No problems in any version of FF, Opera, Chrome/Safari or ie8.

<p style="margin-bottom: 20px;">Hello world!</p>
<div style="float: left; display: inline">
    Hello world, part deux.
</div>

Of course, removing the float from the div remedies the problem. Which ie/CSS bug is this, if any, and what should I search for to figure out how to fix it?

p.s. I cannot assign a width to the div, unfortunately.

A: 

I think you might be encountering the issue explained here. Unfortunately, part of the fix is to give the <div> a width and make it display: inline, things you either can't do or have already done. Maybe it will help you understand why it's happening though...

Cory Larson
I appreciate the input, but my situation is not the double-margin bug.
Jeff
+2  A: 

float: left will essentially cause your DIV container to be pushed to the top leftmost position possible within the document flow. In this case, since the previous P tag is not floated, the margin bottom is disregarded. This would have the desired effect, although not very clean code:

<p style="float: left; display: inline; margin-bottom: 20px;">Hello world!</p>
<div style="clear: left; float: left; display: inline">
    Hello world, part deux.
</div>

It would be ideal, however, to simply remove the float from your element and leave them as they were intended to be (block level elements):

<p style="margin-bottom: 20px;">Hello world!</p>
<div>Hello world, part deux.</div>

Perhaps I am missing the intended effect of these two containers in your case.

cballou
I think you're on to it... I want the `p` to stretch all the way across the parent div (with a bg-color, etc.) and have a `margin-bottom` of 20px. The div(s) below it should be floated left.
Jeff
do you really need the div to be floated for any given reason? is it not supposed to span the full width?
cballou
Yes, it should be floated left because there will be several divs next to it (to the right of it)... containing form controls. I left them off the code above to keep it simple.
Jeff
I really appreciate the input. The only way I've found to make happen what I need to happen is to apply a `border-bottom` to the `p` of the same bg-color as the container. Don't like it, but that's what I did.
Jeff
You should try wrapping all of the floated DIVs in a parent DIV **<div style="overflow:hidden"></div>** which will obey the margin-bottom of your P and will also clear your floats of it's contained children.
cballou