CSS :last-child 选择器

定义和用法

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

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

 

浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主流浏览器都支持last-child选择器。

注意: :last-child 不支持 IE8 及更早的IE版本。

 

实例

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

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

在线运行