CSS参考手册
选择 | Selectors
:visited
:visited
CSS 伪类只选择已访问过的链接。
a:visited {
color: #4b2f89;
}
这种风格可以通过其他任何与链接相关的伪类中重写,即出现在后续规则中的:link
,:hover
和:active
。为了设定合适的链接样式,您需要将:visited
规则放在:link
规则之后,且放在在LVHA顺序中定义的其他规则之前::link
- :visited
- :hover
- :active
。
注:出于保护隐私的原因,浏览器的严格限制你可以为此伪类所选择出的元素应用的样式:只有color
,background-color
,border-color
,border-bottom-color
,border-left-color
,border-right-color
,border-top-color
,outline-color
,column-rule-color
,fill
和stroke
。还要注意,alpha分量将被忽略:使用not-visited规则的alpha分量(除非不透明度opacity是0
,在这种情况下,整个颜色被忽略,并且使用了未被访问的规则之一) 。
虽然颜色可以更改,但是方法getComputedStyle
会说谎,并且总是归还未访问的颜色的价值。
想要了解有关于这些限制和为什么设置这些限制的更多信息,请参阅Privacy
和:visited selector
。
语法
:visited
实例
a:visited { color: #4b2f89; }
a:visited { background-color: white }
规范
Specification |
Status |
Comment |
---|---|---|
HTML Living StandardThe definition of ':visited' in that specification. |
Living Standard |
|
Selectors Level 4The definition of ':visited' in that specification. |
Working Draft |
No change. |
Selectors Level 3The definition of ':visited' in that specification. |
Recommendation |
No change. |
CSS Level 2 (Revision 1)The definition of ':visited' in that specification. |
Recommendation |
Lift the restriction to only apply it for <a> element. Let browsers restricts its behavior for privacy reasons. |
CSS Level 1The definition of ':visited' in that specification. |
Recommendation |
Initial definition. |
浏览器兼容性
Feature |
Chrome |
Edge |
Firefox (Gecko) |
Internet Explorer |
Opera |
Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support |
1.0 |
(Yes) |
1.0 (1.7 or earlier) |
3.5 |
3.5 |
1.0 |
Restrictions in CSS properties allowed in a statement using :visited |
6 |
(Yes) |
4.0 (2.0) |
8 (or earlier) |
? |
5.0 |
Feature |
Android |
Edge |
Firefox Mobile (Gecko) |
IE Phone |
Opera Mobile |
Safari Mobile |
---|---|---|---|---|---|---|
Basic support |
4.4 |
(Yes) |
1.0 (1.0) |
11 |
37 |
9.3 |
选择 | Selectors相关
层叠样式表( Cascading Style Sheets )是一种用来表现 HTML 或 XML 等文件样式的计算机语言。CSS 不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。