为什么要做锚类伪类a:link,:visited,:hover,:active需要以正确的顺序吗? [英] Why do anchor pseudo-classes a:link, :visited, :hover, :active need to be in correct order?

查看:225
本文介绍了为什么要做锚类伪类a:link,:visited,:hover,:active需要以正确的顺序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 W3 Schools ,锚元素上的伪类的顺序为申报是至关重要的。

According to W3 Schools the order that the pseudo classes on the anchor element are declared is vitally important.

为什么?

推荐答案

这里有详细的描述:

http://meyerweb.com/eric/css/link-specificity.html

它与CSS特性有关。

引用自:

It is related to CSS specificity.
Citing from there:

所有这些都可以应用于超链接,在某些情况下,可以应用多个。例如,未访问的链接可以悬停和活动,同时它是未访问的链接。由于上述规则中的三个适用于超链接,并且选择器都具有相同的特异性,则上面列出的一个胜出。因此,活动样式将永远不会出现,因为它将始终被悬停样式覆盖。现在考虑已经访问的超链接。它总是永远是紫色的,因为它的被访问风格击败了任何其他状态,包括活动和悬停。
 
这就是为什么CSS1中的推荐顺序如下:

All of them can apply to a hyperlink, and in some cases, more than one will apply. For example, an unvisited link can be hovered and active at the same time as it's an unvisited link. Since three of the above rules apply to the hyperlink, and the selectors all have the same specificity, then the last one listed wins. Therefore, the "active" style will never appear, because it will always be overridden by the "hover" style. Now consider a hyperlink which has been visited. It will always and forever be purple, because its "visited" style beats out any other state, including "active" and "hover."
 
This is why the recommended order in CSS1 goes like this:

A:链接

A:已访问

A:悬停

:active

A:link
A:visited
A:hover
A:active

BTW W3学校不是形式定义的最佳资源。您最好前往 w3c 访问来源。例如,它不是至关重要,但它是建议。

BTW W3 Schools is not the best resource for formal definitions. You are better off going to the source, at w3c. For example, it is not "vitally important", but it is recommended.

这篇关于为什么要做锚类伪类a:link,:visited,:hover,:active需要以正确的顺序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆