Skip to content Skip to sidebar Skip to footer

Text Color Of Link With "active" Class

I have a navigation bar, and I need the active page, marked by 'subactive' class on the li element to have white text instead of black. The HTML and CSS can be found here: http://j

Solution 1:

That's largely due to how CSS "weighs" the styles. IDs always have more presidence over a standard tag name, class name or pseudo-class. A simple solution is to be as-specific with your anchor class applying the "Active" styling as you are with the rest of the standard elements. Basically:

.subactivea

Should become

#sidenav.subactivea

If that doesn't work for your schema, you'll need to either turn #sidenav in to a class, or work-around it some other way.


By the way, what I was referring to earlier is a style's specificity. As it currently stands, your styles weigh in like so:

#sidenavaa=0, b=1, c=0, d=1 -> specificity = 0,1,0,1.subactiveaa=0, b=0, c=1, d=1 -> specificity = 0,0,1,1#sidenav.subactiveaa=0, b=1, c=1, d=1 -> specfiicity = 0,1,1,1

Almost think of it like this:

(a * 1000) + (b * 100) + (c * 10) + d

The style with the highest number wins.

Solution 2:

Either add !imporatant:

.subactivea
{
    color: #fff!important;

    /**/

}

Or increase the specificity of the definition:

http://www.w3.org/TR/CSS2/cascade.html#specificity

Solution 3:

I wouldn't use the !important if I didn't need to.

To make it work I would replace the line

#sidenava:hover, .subactivea

to

#sidenava:hover, #sidenav.subactivea:link

and remove the code below which doesn't seem to be used

.subactivea
{
   color: #fff;
   background-color: #034676;
}

​ Check out the working example on http://jsfiddle.net/a4hBz/1/

Post a Comment for "Text Color Of Link With "active" Class"