2025年伪类选择器用法(伪类选择器有哪几个属性)

伪类选择器用法(伪类选择器有哪几个属性)选择器 例子 例子描述 active a active 匹配被点击的链接 checked input checked 匹配处于选中状态的 lt input gt 元素 disabled input disabled 匹配每个被禁用的 lt input gt 元素 empty p empty 匹配任何没有子元素的 lt p gt

大家好,我是讯享网,很高兴认识大家。

 选择器 例子 例子描述 :active a:active 匹配被点击的链接

:checked input:checked 匹配处于选中状态的 <input> 元素

:disabled input:disabled 匹配每个被禁用的 <input> 元素

:empty p:empty 匹配任何没有子元素的 <p> 元素

:enabled input:enabled 匹配每个已启用的 <input> 元素

:first-child p:first-child 匹配父元素中的第一个子元素 <p>,<p> 必须是父元素中的第一个子元素

:first-of-type p:first-of-type 匹配父元素中的第一个 <p> 元素

:focus input:focus 匹配获得焦点的 <input> 元素

:hover a:hover 匹配鼠标悬停其上的元素

:in-range input:in-range 匹配具有指定取值范围的 <input> 元素

:invalid input:invalid 匹配所有具有无效值的 <input> 元素


讯享网

:lang(language) p:lang(it) 匹配每个 lang 属性值以 “it” 开头的 <p> 元素

:last-child p:last-child 匹配父元素中的最后一个子元素 <p>, <p> 必须是父元素中的最后一个子元素

:last-of-type p:last-of-type 匹配父元素中的最后一个 <p> 元素

:link a:link 匹配所有未被访问的链接

:not(selector) :not(p) 匹配每个非 <p> 元素的元素

:nth-child(n) p:nth-child(2) 匹配父元素中的第二个子元素 <p>

:nth-last-child(n) p:nth-last-child(2) 匹配父元素的倒数第二个子元素 <p>

:nth-last-of-type(n) p:nth-last-of-type(2) 匹配父元素的倒数第二个子元素 <p>

:nth-of-type(n) p:nth-of-type(2) 匹配父元素的第二个子元素 <p>

:only-of-type p:only-of-type 匹配父元素中唯一的 <p> 元素

:only-child p:only-child 匹配父元素中唯一的子元素 <p>

:optional input:optional 匹配不带 “required” 属性的 <input> 元素

:out-of-range input:out-of-range 匹配值在指定范围之外的 <input> 元素

:read-only input:read-only 匹配指定了 “readonly” 属性的 <input> 元素

:read-write input:read-write 匹配不带 “readonly” 属性的 <input> 元素

:required input:required 匹配指定了 “required” 属性的 <input> 元素

:root root 匹配元素的根元素,在 HTML 中,根元素永远是 HTML

:target #news:target 匹配当前活动的 #news 元素(单击包含该锚名称的 URL)

:valid input:valid 匹配所有具有有效值的 <input> 元素

:visited a:visited 匹配所有已经访问过的链接

小讯
上一篇 2025-05-11 10:17
下一篇 2025-05-05 16:03

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/149666.html