CSS:a:link与仅一个(不带:link部分) [英] CSS: a:link vs just a (without the :link part)
问题描述
因此我们需要对CSS锚伪类使用以下顺序
a:link { color: red }
a:visited { color: blue }
a:hover { color: yellow }
a:active { color: lime }
但是我的问题是,为什么要麻烦a:link部分?相反,以上内容(也许不是很清楚)相对于:
有什么优势?a { color:red; } /* notice no :link part */
a:visited { color: blue; }
etc.,etc.
:link
选择未访问的链接,即:浏览器未访问的具有href
属性的锚点(对于浏览器供应商具有的任何定义)代表访问过").
如果它具有:link
,则它将永远不匹配<h1><a name="foo">A foo to be linked to</a></h1>
(尽管这些天您应该使用<h1 id="foo">A foo to be linked to</h1>
.)
除此之外,它的用途更加明确.
a { color: orange }
a:link { color: blue }
a:visited { color: indigo }
a:hover { color: green }
a:active { color: lime }
<a>my anchor without href</a>
<br><br>
<a href="http://somelinkhere.com">my anchor without href</a>
(它们也具有不同级别的特异性)>
So we're required to use the following order for CSS anchor pseudo-classes
a:link { color: red }
a:visited { color: blue }
a:hover { color: yellow }
a:active { color: lime }
But my question is why bother with the a:link part? Rather, is there any advantage to the above (other than perhaps clarity) over:
a { color:red; } /* notice no :link part */
a:visited { color: blue; }
etc.,etc.
:link
selects unvisited links, that is: anchors with an href
attribute which have not been visited by the browser (for whatever definition the browser vendor has for "visited").
If it has :link
then it will never match <h1><a name="foo">A foo to be linked to</a></h1>
(Although you should be using <h1 id="foo">A foo to be linked to</h1>
these days.)
Aside from that, it does make it clearer what it is for.
a { color: orange }
a:link { color: blue }
a:visited { color: indigo }
a:hover { color: green }
a:active { color: lime }
<a>my anchor without href</a>
<br><br>
<a href="http://somelinkhere.com">my anchor without href</a>
(They also have different levels of specificity)
这篇关于CSS:a:link与仅一个(不带:link部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!