CSS:a:link 与仅 a(不带 :link 部分)
所以我们需要对 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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
:link
选择未访问的链接,即:具有浏览器未访问过的href
属性的锚点(无论浏览器供应商对“已访问”的定义是什么)。如果它有
:link
那么它永远不会匹配要链接到的 foo
< /code>
(尽管现在您应该使用
A foo 链接到
。)
除此之外,它确实使人们更清楚什么它是为了。
(它们还具有不同级别的特异性)
:link
selects unvisited links, that is: anchors with anhref
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.
(They also have different levels of specificity)
仅“a”指的是所有可能的链接(未访问的、已访问的、悬停的和活动的),而“a:link”仅指正常的未访问的链接。
如果您使用“a”而不是“a:link”,则将所有链接的默认 CSS 设置为“a”的设置。在这种特定情况下,由于您指定了每个可能的伪类,因此您是否说“a:link”或只是“a”本质上并不重要。
因此,在第一组中,您写出所有伪类(a:link,a :visited 等),您正在为“a”内的每种可能情况指定 CSS
在第二组中,您只需编写“a”,您实际上是为您在第一行中编写的内容的所有链接设置默认 CSS ,然后为其他伪类重新定义 CSS
Just "a" refers to ALL possible links (unvisited, visited, hovered, and active), whereas "a:link" just refers to normal unvisited links.
If you use "a" instead of "a:link", you are setting the default CSS for ALL links to whatever "a" is set to. In this specific case, since you specify each possible pseudoclass, it essentially doesn't matter whether you say "a:link" or just "a"
So in the first group, where you write out all the pseudoclasses (a:link, a:visited, etc), you are specifying the CSS for each possible case WITHIN "a"
In the second group, where you just write "a", you are actually setting the default CSS for all links to what you write in the first line, then redefining the CSS for the other pseudoclasses
http://www.w3schools.com/css/css_pseudo_classes.asp
:链接是当链接未被访问时。因此,当存在带有 href 属性的锚点并且用户从未访问过该锚点后面的页面时。
http://www.w3schools.com/css/css_pseudo_classes.asp
:link is when the link is unvisited. So when there is an anchor with a href attribute and the user have never been on the page behind the anchor.
选择器
:link
是超链接的伪元素选择器,任何是超链接的元素都会被匹配。a
选择器将“仅”匹配锚元素。通常,每个
a
元素也是一个超链接,我自己不知道有什么方法可以在不使用锚,因此在大多数情况下您可以使用它们中的任何一个。但是,仅使用
a
将匹配非超链接的锚元素。例如,以Sign up form
编写的锚元素将与超链接伪元素:link
选择器不匹配但会匹配a
选择器。Selector
:link
is a pseudo-element selector for hyperlinks, any element that is an hyperlink will be matched. Thea
selector will match "only" anchor elements.Normally, every
a
element is also a hyperlink, and I'm not aware myself of any way to create an hyperlink in HTML without using an anchor, so you can probably use either of them in most cases.However, using only
a
will match anchor elements that are not hyperlinks. For example, an anchor element written this way<a name=sign-up>Sign up form</a>
will not match the hyperlink pseudo-element:link
selector but will match thea
selector.