2

I was reading about :visited pseudo class on MDN and they said that :visited pseudo class can be overridden by :link pseudo class:

The :visited CSS pseudo-class lets you select only links that have been visited. This style may be overridden by any other link-related pseudo-classes, that is :link

I am not able recreate this feature. I tried two scripts. One with :link mentioned before :visited and then the other way round but both the scripts work the same. In the following script the :link pseudo class doesn't override the :visited pseudo class -- The anchor element becomes red when it is visited not green.

a:visited {
  color: red;
}
a:link {
  color: green;
}
<a href="http://www.hello.com">Go to Hello.com </a>

So, how does :visited pseudo class get overridden by :link pseudo class? Would there be any observable difference if :link is declared after or before :visited in the style sheet?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
user31782
  • 7,087
  • 14
  • 68
  • 143

1 Answers1

3

I think that this is a slight error in the documentation.

The real problem is that, if visited, the :link pseudo class no longer aplies ,in any case

The :link CSS pseudo-class lets you select links inside elements. This will select any link which has not yet been visited,

cited also from MDN

So, in your examples, :link won't work in any case, no matter what you do, once the link is visited

vals
  • 61,425
  • 11
  • 89
  • 138
  • But this is obvious. This is what `:visited` is supposed to do. I thought mentioning `:visited` before `:link` would override `:visited` in such a way that the the properties would be solely determined by `:link` pseudo class no matter whether the link is visited or not -- but it doesn't happen. Ordering of `:link` and `:visited` doesn't matter. `:link` styles only unvisited links and `:visited` styles the visited ones. They are both mutually exclusive. – user31782 Mar 05 '16 at 10:19
  • @user31782: "But this is obvious." So what is your point, exactly? How does this answer not address your question? – BoltClock May 10 '16 at 06:50
  • @BoltClock The answer exactly addresses my question. By _But this is obvious_ I meant that it is so obvious that _if visited, the :link pseudo class no longer applies_. – user31782 May 10 '16 at 06:58