css文件——css的选择器—编号2

nth-child()

Odd 和 event

Odd 和 even 是可用于匹配下标是奇数或偶数的子元素的关键词(第一个子元素的下标是 1)。
w3c的实例

:nth-child(2)

使用公式 (an + b)。描述:表示周期的长度,n 是计数器(从 0 开始),b 是偏移值。
w3c的实例

这个父盒子中所有p标签 第二个是否是p标签 是改变背景颜色 否 不变
p:nth-child(2)
{
background:#ff0000;
}

规定属于其父元素的第二个子元素的每个 p 的背景色:
w3c的实例

:last-child
p:last-child
{ 
background:#ff0000;
}

:last-child 选择器匹配属于其父元素的最后一个子元素的每个元素。

提示:p:last-child 等同于 p:nth-last-child(1)。

:first-child

p:first-child
{
background-color:yellow;
}
:first-child 选择器用于选取属于其父元素的首个子元素的指定选择器。
w3网页地址

:first-of-type
:first-of-type 选择器匹配属于其父元素的特定类型的首个子元素的每个元素。
提示:等同于 :nth-of-type(1)。

w3c的实例( :first-of-type )

猜你喜欢

转载自blog.csdn.net/qq_48957847/article/details/113757918