If I have this CSS:
a:link { color: blue; } a:hover { color: red; } #someID a:link { color: black; }
Links under the ID always appears in black on hover. I’m aware that using an ID gives a higher priority, however, I’m not overriding the :hover selector, only the :link selector, so shouldn’t the hover display in red?
The
:linkpseudo class applies to the link even when you are hovering over it. As the style with the id is more specific it overrides the others.The only reason that the
:hoverstyle overrides the:linkstyle at all is that it comes later in the style sheet. If you place them in this order:the
:linkstyle is later in the style sheet and overrides the:hoverstyle. The link stays blue when you hover over it.To make the
:hoverstyle work for the black link you have to make it at least as specific as the:linkstyle, and place it after it in the style sheet: