views:

548

answers:

4

Is there an clean alternative that doesn't make the text disappear in the following:

<div style="background-color:#ddd; padding:10px 0 50px 0;">
<ol><li>In what year were you born?</li></ol>
<div><select name="c_record" size="1">
    <option value="">-- Select One --</option>
    <option value="1">1900</option>
    <option value="2">1902</option>
</select></div>
</div>

If I change the padding on the outside div to: padding:10px 0 0 0; the text shows up again.

I have also tried adding a second div inside the outmost div and adding the padding to it, but that doesn't work either. Add margin to this inside div doesn't have any affect for the top and bottom margins.

Any ideas?

Edit: I am using IE 6 & 7 and I have no other code on the page, no doctype, stylesheets--just the above code.

A: 

Try margin instead of padding?

jeffamaphone
Margin doesn't work because I need the background to show up.
Darryl Hein
u could still use margins and have a div below it that holds the background.
Samuel
Tried that, but it caused the same problem (updated the question).
Darryl Hein
A: 

Are these the only styles? If there is anything floating things get complicated fast. Please try this in it's own file with just the doctype, html, head, etc. There is nothing wrong with the above, in isolation.

Adam Luter
I have removed everything else on the page, so there is only this, no other stylesheets, to doc type, nothing...just this.
Darryl Hein
+3  A: 

Adding position:relative; to your style will fix this problem. It's called affectionately the Peekaboo bug.

Here is a link that explains it in a little more detail.

I would agree that you should just try using margin though since adding position:relative can cause other problems. Also browsers don't consistently follow the box model standard with padding.

Dave L
Unfortunately the padding and margin either breaks it or doesn't work when within the other div without the padding. The relative fixes it and for the page it's on, nothing else is floating so we should be good....till I decide to float something.
Darryl Hein
If you float something you can always use height: 1% to provide the same fix.
Jeremy B.
A: 

I am using IE 6 & 7 and I have no other code on the page, no doctype, stylesheets--just the above code.

It is just foolish to try to solve problems by letting IE default to quirks mode.

In any case, @Jeremy B has a good solution with the height: 1%. This works just fine for me in IE6:

<div style="background-color:#ddd; padding:10px 0 50px 0; height: 1%;">
Traingamer
On the page with the rest of the HTML, it also doesn't work properly and isn't running in quirks mode. This was purely to test if it was something else or just plain the way IE works.
Darryl Hein
So does a 'height: 1%' or another trigger of 'haslayout' work in your page? Or in your example, above?
Traingamer