CSS3 :first-of-type 选择器

约 237 字 更新于 2026-11-18 5iyo.com

CSS3 :first-of-type 选择器

实例

选择的 p 元素是其父元素的第一个 p 元素:

p:first-of-type { background:#ff0000; }


定义和用法

:first-of-type 选择器匹配元素其父级是特定类型的第一个子元素。

提示: 和 :nth-of-type(1) 是一个意思。


浏览器支持

表格中的数字表示支持该属性的第一个浏览器版本号。

选择器
:first-of-type 4.0 9.0 3.5 3.2 9.6