天天看点

CSS3 :last-child 选择器

CSS3 :last-child 选择器

完整CSS选择器参考手册

指定父元素中最后一个p元素的背景色:

p:last-child

{

background:#ff0000;

}

:last-child 选择器用来匹配父元素中最后一个子元素。

<b>提示:</b> p:last-child 等同于 p:nth-last-child(1)。

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

选择器

:last-child

4.0

9.0

3.5

3.2

9.6

指定父元素 ul 中最后一个 li 元素,并设置背景颜色:

li:last-child {

background-color: #ff0000;

CSS3 :last-child 选择器