:nth-of-type(), :nth-last-of-type()

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

在一个父元素里的子元素,使用 :nth-of-type() 可以按类型和位置来选择这些子元素 .. 比如选择所有在父元素里,排在第1位置的图像元素 … 这个伪类的参数跟之前介绍的 :nth-chlid() 的参数的使用是一样的 .. 可以使用数字,关键词,还有表达式  …

另外还有一个 :nth-last-of-type() 伪类 .. 它可以倒过来数元素的位置 …

在这个文档里, .container 这个元素的下面有很多子元素 … 如果我们想要选中第二个 p 元素 …

p:nth-of-type(2) {
background-color: #FCEBBD;
color: #AF9540;
padding: 20px;
}

选中第一个,可以使用数字 1 …

下面再去看一下 :nth-last-of-type() …. 比如要选中倒数第一个 p 元素 …

p:nth-last-of-type(1) {
background-color: #FCEBBD;
color: #AF9540;
padding: 20px;
}

选择倒数第二位置上的 p 元素 .. 可以使用数字 2 …

:nth-of-type(), :nth-last-of-type()《 CSS:选择器 》

统计

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

社会化网络

关于

微信订阅号

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