:first-of-type, :last-of-type

0
视频
0
完成
0%
进度
0
分钟
0
完成
0%
进度

:first-of-type 这个伪类表示父元素里某个类型的第一位置上的元素 … 它相当于是 :nth-of-type(1) … 还有一个:last-of-type … 表示某个类型最后一个,也就是倒数第一位置上的元素 … 跟 :nth-last-of-type(1) 的效果是一样的 ..

测试

下面我们可以选中这个文档里面,排第一位置的 p 元素 …

p:first-of-type {
background-color: #FCEBBD;
color: #AF9540;
padding: 20px;
}

想要选择排倒数第一的 p 元素 … 可以换成 :last-of-type 这个伪类 …

:first-of-type, :last-of-type《 CSS:选择器 》

统计

14696
分钟
0
你学会了
0%
完成

社会化网络

关于

微信订阅号

扫描微信二维码关注宁皓网,每天进步一点