first-child、last-child、nth-child(n)、nth-of-type(n).
<style>
/*选择属于其父元素的首个子元素的每个 <p> 元素,并为其设置样式*/
p:first-child{
background: yellow;
}
/*指定属于其父元素的最后一个子元素的 p 元素的背景色*/
p:last-child{
background: dodgerblue;
}
/*选择在父类元素中处于第一个或最后一个位置p元素*/
</style>
<style>
/*规定属于其父元素的第n个子元素的每个 p 的背景色:*/
p:nth-child(2){
background: dodgerblue;
}
/*找到在父元素中中处于第n位的 p 元素*/
</style>
<style>
/*规定属于其父元素的第二个 p 元素的每个 p:*/
p:nth-of-type(2){
background: red;
}
/*找到在某个子元素列表中的第 n个 p元素*/
</style>