tags:

views:

55

answers:

4

I have the following HTML

<div id="nav" class="red">

some more HTML here

</div>

The following CSS:

#nav.red {
background: red;
}

However this does not work in IE6, can anyone help?

+1  A: 

just use

#nav

.red { 
    background: red; 
} 
wefwfwefwe
ID's must be unique.
Daniel A. White
I cant do that, I want nav to be any colour I want based on the class I add.
danit
use ".red { background: red; }" instead then
wefwfwefwe
"ID's must be unique." what's that got to do with anything?
wefwfwefwe
Bad code, what if you wanted to change the colour scheme? Changing all your classes is bad. Better: semantic names.
Niels Bom
A: 

There is a mistake. Try this:

#nav, .red {
background: red;
}
phpogo
That styles both the `#nav` div (regardless of class) and anything else that might have the `red` class.
Thorarin
+3  A: 

At this moment it is unknown why this is the case, and there is no real 'fix'. You just have to work around it by changing your CSS. For example:

#nav{
   /*basic styles*/
}
   .red{
      /* stylings */
   }
   .blue{
      /* stylings */
   }
   .contact{
      /* stylings */
   }
   .news{
      /* stylings */
   }

See here for more, and here for a test page.

Dominic Rodger
A: 

You could use ie7.js to fix the bug. It makes IE6 behave more like IE7. It should fix atleast the multiple classes-problem, so might work for #id.class also. More info about ie7.js

Otherwise, you have to work around it. For example

<div id="nav">
   <span class="red">hep</span>
   <span>hep</span>
</div>

and CSS

#nav {}
#nav span {color:#000;}
#nav .red {color:#f00;}

Or if you can, you could just do the colour-changing with the .red and use #nav for the common layout-stuff. eg.

#nav {float:left; padding:10;}
.red {background: #f00;}
.blue {background: #00f;}
Marcus