Forum Moderators: not2easy

Message Too Old, No Replies

Nested div formatting

         

bobjunga

5:01 am on Apr 7, 2004 (gmt 0)

10+ Year Member



I want to add an empty div around another div (see below for reason why, if interested), but when I do the first div looses most of its formatting.

Example:

before:
<div id="content"> ... stuff </div>

after:
<div id="foo"><div id="content"> ... stuff </div></div>

css (for both)
#content {border:1px solid #00FF00; background-color:#00FF00;}

In the before version, I see the border and background color on the 'content' div, but in the after version, the border and background on #content have no effect (margin seems to continue working). I tried putting the styles inline and they still do not work when the 'foo' div is present.

Why is this?

The reason:
The id of the wrapper div is actually a Dreamweaver template variable -- <div id="@@(SectionName)@@> This way I would be able to specify common formatting for the content area...

#content {this and that...}

and also override formatting for a particular section on my site...

#Products #content {color:blue;}

I am not using both class and id for this because there are actually several layers -- Section->SubSection->Page

--BobG

Rambo Tribble

5:33 am on Apr 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In the example you provided, the id's quotes aren't closed.

mach

9:55 am on Apr 7, 2004 (gmt 0)

10+ Year Member



Can you give use the full code? Sometimes there are little things that you don't notice that mess things up.

grahamstewart

10:33 am on Apr 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds like normal usage to me.
Have you tried validating the code?

W3C HTML Validator [validator.w3.org]
W3C CSS Validator [jigsaw.w3.org]

bobjunga

2:58 pm on Apr 7, 2004 (gmt 0)

10+ Year Member



Thanks for the good advice. I had been using DW's 'validate markup' but I found that the w3c validator caught some things that DW did not. It did not help however.

Next I made a minimal test page and it works fine.

So now I am copying code from the problem page to the test page a little at a time until it breaks.

I just wanted to give an update that you guys have put me on the right path.

--BobG

bobjunga

3:34 pm on Apr 7, 2004 (gmt 0)

10+ Year Member



OK, I can reproduce this bug(?) in a minimum test page (source at the end) which validates. Note that I am seeing this strange behavior in IE 6.

On the test page 'hello' should have a green background because of the #foo style, but the presence of div "myid" around the div "foo" causes the foo formating not to be applied.

This only happens when the div are inside a relative positioned div ('layout' in this example) *with* a width specified.

There are several work arounds.

1) if either "myid" or "foo" have "position:relative" the problem goes away.

2) if you put any comment before div "myid" the problem goes away!

Wierd stuff.

--BobG

---------------- cut ------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>IE Parse Bug?</title>
<style type="text/css">
#layout
{
position:relative;
width:800px;
}
#foo {background-color:#00CC00;}
</style>

</head>

<body>
<div id="layout">

<div id="myid">
<div id="foo">hello</div>
</div>

</div>
</body>
</html>
---------------- cut ------------------------

grahamstewart

5:46 pm on Apr 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It can be solved by giving #foo a dimension (like width:100%).

No idea why it is happening tho.

mach

9:20 pm on Apr 7, 2004 (gmt 0)

10+ Year Member



Definitely seems like a bug to IE in me.