0

I know it's a stupid question.

I always wondered what is the difference between:

.test a {}
or
.test a:link {}

I did several tests, they look the same.

what changes?

  • On top of what the existing answers already said so far: Using just `a` as selector will format any `a` elements, whereas `:link` or `a:link` will only apply to those that have a (non-empty) `href` attribute set. (Granted, it is rather rare to have `a` elements without `href`, but sometimes it might occur for various reasons.) – CBroe Sep 20 '15 at 22:23

2 Answers2

0

the :link selector is used to style the unvisited links. For example, the following would change the font-size of the unvisited links.

a:link {
    font-size:14px;
}
Sohrab Hejazi
  • 1,441
  • 6
  • 18
  • 29
0

6.6.1.1. The link pseudo-classes: :link and :visited

User agents commonly display unvisited links differently from previously visited ones. Selectors provides the pseudo-classes :link and :visited to distinguish them:

  • The :link pseudo-class applies to links that have not yet been visited.
  • The :visited pseudo-class applies once the link has been visited by the user.

After some amount of time, user agents may choose to return a visited link to the (unvisited) ‘:link’ state.

The two states are mutually exclusive.

Moreover, adding the :link pseudo-class increases the specificity:

A selector's specificity is calculated as follows:

  • count the number of ID selectors in the selector (=a)
  • count the number of class selectors, attributes selectors, and pseudo-classes in the selector (=b)
  • count the number of type selectors and pseudo-elements in the selector (=c)
  • ignore the universal selector
Oriol
  • 274,082
  • 63
  • 437
  • 513
  • marking it as a duplicate and submitting an answer stops anyone else from submitting an answer. This is seen as a monopoly on Stack. Wasn't marking it as a duplicate not enough? – Funk Forty Niner Sep 20 '15 at 23:54
  • @Fred-ii- First I searched a bit and found no duplicate, so I posted an answer. Then I remembered having seen the duplicate, so I searched better and found it. If this seems a conflict of interests, I can delete my answer (but first it should be unaccepted). – Oriol Sep 21 '15 at 00:19
  • Or reopen it. You did write a good answer. – Funk Forty Niner Sep 21 '15 at 00:32