CSS3 :last-child 选择器
指定父元素中最后一个p元素的背景色:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
p:last-child {
background: #ff0000;
}
</style>
</head>
<body>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
</body>
</html>
定义和用法
:last-child选择器用来匹配父元素中最后一个子元素。
提示: p:last-child等同于p:nth-last-child(1)。
浏览器支持
| 选择器 | |||||
|---|---|---|---|---|---|
| :last-child | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
完整CSS选择器参考手册