首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

:visited

:visitedCSS 伪类只选择已访问过的链接。

代码语言:javascript
复制
a:visited {
  color: #4b2f89;
}

这种风格可以通过其他任何与链接相关的伪类中重写,即出现在后续规则中的:link:hover:active。为了设定合适的链接样式,您需要将:visited规则放在:link规则之后,且放在在LVHA顺序中定义的其他规则之前::link- :visited- :hover- :active

注:出于保护隐私的原因,浏览器的严格限制你可以为此伪类所选择出的元素应用的样式:只有colorbackground-colorborder-colorborder-bottom-colorborder-left-colorborder-right-colorborder-top-coloroutline-colorcolumn-rule-colorfillstroke。还要注意,alpha分量将被忽略:使用not-visited规则的alpha分量(除非不透明度opacity是0,在这种情况下,整个颜色被忽略,并且使用了未被访问的规则之一) 。

虽然颜色可以更改,但是方法getComputedStyle会说谎,并且总是归还未访问的颜色的价值。

想要了解有关于这些限制和为什么设置这些限制的更多信息,请参阅Privacy:visited selector

语法

代码语言:javascript
复制
:visited

实例

代码语言:javascript
复制
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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com