伪类

CSS伪类是添加到选择器的关键字,指定要选择的元素的特殊状态。例如,:hover 将在用户悬停在选择器指定的元素上时应用样式。

伪类连同伪元素一起, 他们允许你不仅仅是根据文档DOM树中的内容对元素应用样式,而且还允许你根据诸如像导航历史这样的外部因素来应用样式(:visited, 为例), 同样的,可以根据内容的状态 (例如 在一些表单元素上的 :checked ), 或者鼠标的位置 (例如 :hover 让你知道是否鼠标在一个元素上悬浮)来应用样式.

语法

selector:pseudo-class { property: value; }

标准伪类索引

规范

规范 Status Comment
Fullscreen API Living Standard Defined :fullscreen.
WHATWG HTML Living Standard Living Standard No change from HTML5.
Selectors Level 4 Working Draft Defined :any-link:local-link:scope:active-drop-target:valid-drop-target:invalid-drop-target:current:past:future:placeholder-shown:user-error:blank:nth-match():nth-last-match():nth-column():nth-last-column(), and :matches().
No significant change for pseudo-classes defined in Selectors Level 3 and HTML5 (though semantic meaning not taken over).
HTML5 Recommendation Defined the semantic meaning, in the HTML context, of :link:visited:active:enabled:disabled:checked, and :indeterminate.
Defined :default:valid:invalid:in-range:out-of-range:required:optional:read-only:read-write, and :dir().
CSS Basic User Interface Module Level 3 Candidate Recommendation Defined :default:valid:invalid:in-range:out-of-range:required:optional:read-only, and :read-write, but without the associated semantic meaning.
Selectors Level 3 Recommendation Defined :target:root:nth-child():nth-last-of-child():nth-of-type():nth-last-of-type():last-child:first-of-type:last-of-type:only-child:only-of-type:empty, and :not().
Defined the syntax of :enabled:disabled:checked, and :indeterminate, but without the associated semantic meaning.
No significant change for pseudo-classes defined in CSS Level 2 (Revision 1).
CSS Level 2 (Revision 1) Recommendation Defined :lang():first-child:hover, and :focus.
No significant change for pseudo-classes defined in CSS Level 1.
CSS Level 1 Recommendation Defined :link:visited, and :active, but without the associated semantic meaning.

相关链接

文档标签和贡献者

 此页面的贡献者: Ende93, xgqfrms-GitHub, teoli, alimon
 最后编辑者: Ende93,