tags:

views:

386

answers:

2

I have some css like so

#menu li
{
   color:#336633;
}
.hover
{
   color:#ffffff;
   background-color:#336633;
}

I am using jQuery's hover like so on hover: addClass('hover'); on out: removeClass('hover');

This changes the background color but not the font color. I suspect this is because the class is being applied first and then the default li behavior gets applied? Is there an easy way to make this work? I don't want to use a class for default li behavior, then remove it, apply hover and reapply default.

Thanks

+1  A: 

What is the order in which these statements appear in your CSS? For the above code to work, .hover class MUST appear after the #menu li definition.

Alternatively, you can add !important to color property.

.hover
{
   color:#ffffff !important;
   background-color:#336633;
}
SolutionYogi
ordering was right. !important fixed it thanks you
Ori Cohen
The !important declaration doesn't work in ie6.
Joel Potter
BTW, I think this is because id selectors have higher preference than the class selectors. If you had styled your LI using class, then you won't need !important.
SolutionYogi
Joel, IE6 definitely supports !important declaration. Link: http://archivist.incutio.com/viewlist/css-discuss/104195
SolutionYogi
Nice link. I guess I was wrong, it's just the implementation that is sketchy. I've always avoided the use of !important because I consider it a hack.
Joel Potter
I don't think the bug is with !important. The problem is how IE interprets if you specify rule for same property multiple times. If you do that, then it's a hack, otherwise !important works just fine.
SolutionYogi
+1  A: 

Your li selector is more specific than your class selector.

Try:

#menu li
{
   color:#336633;
}
#menu li.hover
{
   color:#ffffff;
   background-color:#336633;
}
Joel Potter
I like your solution better. +1.
SolutionYogi