开发者

css what's the whole point of :link

开发者 https://www.devze.com 2023-03-01 04:16 出处:网络
what\'s the whole point of :link? i mean what\'s the point 开发者_C百科of applying styles to a:link when we can simply apply styles to a ?It references unvisited links.a { } does the same thing, but y

what's the whole point of :link? i mean what's the point 开发者_C百科of applying styles to a:link when we can simply apply styles to a ?


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/


: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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消