元素显示状态伪类
这些伪类可以基于元素的显示状态来选择它们。
:fullscreen
匹配当前处于全屏模式的元素。
输入状态伪类
这些伪类与表单元素相关,可以基于 HTML 属性或交互前后字段的状态来选择元素。
TBD
语言的伪类
这些伪类根据文档语言而反应,可以基于语言或书写方向来选择元素。
:dir()
方向性伪类基于由文档语言所确定的其方向性来选择元素。
:lang()
基于其内容语言来选择元素。
位置伪类
这些伪类与链接以及当前文档中的目标元素有关。
TBD
资源状态伪类
这些伪类应用于能够处于被描述为“正在播放”状态的媒体,例如视频。
TBD
时间方面的伪类
这些伪类适用于查看有计时功能的东西,如 WebVTT 字幕轨。
TBD
树结构的伪类
这些伪类与文档树中的元素位置有关。
:root
表示文档的根元素。在 HTML 中这通常是 元素。
:empty
表示除空白字符外没有子元素的元素。
TBD
用户行为伪类
这些伪类需要用户进行一些交互才能够应用,例如将鼠标指针悬停在元素上。
TBD
函数式伪类
这些伪类接受可容错选择器列表作为参数。
:is()
匹配与提供的列表中的任何选择器匹配的任何元素。
:not()
表示其参数中未表示的任何元素。
:where()
优先级调整伪类匹配与提供的列表中的任何选择器匹配的任何元素,但不添加任何优先级权重。
:has()
该关系伪类表示与任何一个与锚定的元素的相对选择器相匹配(如果有的话)的元素。
语法
cssselector:pseudo-class {
property: value;
}
像常规的类一样,你可以在选择器中将任意数量的伪类链在一起。
字母索引
由一组 CSS 规范定义的伪类包括以下内容:
A
:active
:any-link
:autofill
B
:blank
实验性
C
:checked
:current
实验性
D
:default
:defined
:dir()
实验性
:disabled
E
:empty
:enabled
F
:first
:first-child
:first-of-type
:fullscreen
:future
实验性
:focus
:focus-visible
:focus-within
H
:has()
实验性
:host
:host()
:host-context()
实验性
:hover
I
:indeterminate
:in-range
:invalid
:is()
L
:lang()
:last-child
:last-of-type
:left
:link
:local-link
实验性
M
:modal
N
:not()
:nth-child()
:nth-col()
实验性
:nth-last-child()
:nth-last-col()
实验性
:nth-last-of-type()
:nth-of-type()
O
:only-child
:only-of-type
:optional
:out-of-range
P
:past
实验性
:picture-in-picture
:placeholder-shown
:paused
:playing
R
:read-only
:read-write
:required
:right
:root
S
:scope
:state()
实验性
T
:target
:target-within
实验性
U
:user-invalid
实验性
V
:valid
:visited
W
:where()
规范
Specification
HTML# pseudo-classes
Selectors Level 4
CSS Scoping Module Level 1
CSS Paged Media Module Level 3
参见
伪元素
Help improve MDN
Was this page helpful to you?
Yes
No
Learn how to contribute
This page was last modified on 2025年11月4日 by MDN contributors.
View this page on GitHub • Report a problem with this content