Pacerier
Pacerier

Reputation: 89763

css what's the whole point of :link

what's the whole point of :link? i mean what's the point of applying styles to a:link when we can simply apply styles to a ?

Upvotes: 0

Views: 107

Answers (3)

Boris Zbarsky
Boris Zbarsky

Reputation: 35084

In addition to the fact that :link only matches unvisited links, some <a> elements aren't links at all. Consider <a name="something"> with no href attribute.

Upvotes: 1

Jacob Krall
Jacob Krall

Reputation: 28835

:link only selects unvisited links. So, in the usual case, you are correct that :link is the excluded middle and will inherit any styles from a.

Note as well that you could also do the same thing by styling :link, :hover, and :active, while a would only affect visited links. There's no reason unvisited links are more or less important than other types of links.

However, let's say you just want to make unvisited links have a yellow background, for some reason, but not visited, hover, and active links. Which would you rather do?

a { background-color: yellow; }
a:visited { background-color: transparent; }
a:hover { background-color: transparent; }
a:active { background-color: transparent; }

Or

a:link { background-color: yellow; }

The CSS designers didn't want to limit anyone from doing such a thing, so that is why :link is defined.

Upvotes: 3

user342706
user342706

Reputation:

It references unvisited links. a { } does the same thing, but you can also set a:visited, a:active, a:hover. So its just another way to style the state of the anchor tag. Here is a working jsfiddle that you can see the difference.

http://jsfiddle.net/keroger2k/wfP2U/

Upvotes: 4

Related Questions