tags:

views:

272

answers:

5

I have some css code that shows a background color on hover. The text is white on a blue background.

Otherwise, if there is no hover, the text is blue with a white background. However, when the link has been visited, the text remains blue with a blue background on hover.

How can I force the hover text color to take precedence?

a:link{
    color:#3399cc;
}

a:hover{
    background-color:#3399cc;
    color:#ffffff;
}
a:visited{
    color:#3399cc;
}
a:active{
    color:#3399cc;
}
+2  A: 

if I'm not mistaken, all you have to do is switch the order, put the :hover class after the :visted class in your style sheet

LorenVS
+5  A: 

I think specifying the style data for :hover after the style data for :visited is enough to do the trick:

a:visited{  
    color:#3399cc;  
}  
a:hover{  
    background-color:#3399cc;  
    color:#ffffff;  
}
JorenB
There are several acronyms to remember the proper order for link properties - one is LoVe HAte - Link; Visited; Hover; Active
Traingamer
Didn't know about that one yet - thanks!
JorenB
Las Vegas Hells Angels is another good acronym I just saw.
Dougman
A: 

One method would be to use the !important keyword:

a:visited
{
    color:#3399cc;
}
a:hover
{
    background-color: #3399cc;
    color: #ffffff !important;
}

That will make sure that the :hover takes precedence.

It might also work to replace your a:visited hover, which means a <hover> element (doesn't exist!), with a:visited:hover.

As already mentioned, changing the order of the styles sshould be a sufficient fix: later definitions take precedence over earlier ones.

Eric
please no !important hack. There is always a valid way around such a thing.
corymathews
A: 

See Eric Meyer's article on the subject: Ordering The Link States

It is suggested, that you use the “link-visited-hover-active” LVHA-rule, referring to the order of the pseudo-classes among the CSS rules. The comments bring up some easily recognizable acronyms on the ordering (adding :focus into the pack):

  • Lord Vader's Former Handle, Anakin
  • Lord Vader Froze Hans Ass
A: 

LoVeHAte = link,visited,hover,active

dusoft