tags:

views:

32

answers:

2

Odd CSS behavior. When i set the visited color using CSS(a.nav:hover as below example) then the hover doesn't work once the link is visited by the user. However when i set it with the reference of the parent element(.header a.nav:hover as below) it works. why ?

a.nav:visited{
color:yellow;
}

/*once the link is visited by user this rule not working*/
a.nav:hover{
color:red;
}

/*if we use this rule it works even after the link is visited*/
.header a.nav:hover{
color:red;
}

<div class="header">
<a class="nav" .. >test </a>
</div>
+2  A: 

It sounds like a specificity issue. Do you have any other a pseudo-selectors in your CSS? If there's a selector which is more specific than a.nav:hover (such as .header a.nav:hover) then it will override it, regardless of its position in the file.

Skilldrick
The official CSS2 specification, in case someone wants to read it: http://www.w3.org/TR/CSS21/cascade.html#specificity (and people should read it! the section about selector's specificity is easy to understand)
Denilson Sá
@Denilson Thanks for that. I linked to the one above because I think it's awesome to explain specificity with Star Wars :)
Skilldrick
A: 
a.nav:hover,
a.nav:visited:hover{
color:red;
}

or

a.nav:hover{
color:red !important;
}

Should make it work.

Jacob R