CSS :last-child 伪类
定义和用法
CSS :last-child 伪类用于匹配作为其父元素最后一个子元素的任何元素。
提示:p:last-child 等同于 p:nth-last-child(1)。
实例
为其父元素的最后一个子元素的 <p> 元素指定背景颜色。同时为其父元素的最后一个子元素的 <li> 元素指定背景颜色:
p:last-child {
background-color: yellow;
}
li:last-child {
background-color: yellow;
}
CSS 语法
:last-child {
css declarations;
}
技术细节
| 版本: | CSS3 |
|---|
浏览器支持
表格中的数字指定了完全支持该伪类的首个浏览器版本。
| Chrome | Edge | Firefox | Safari | Opera |
|---|---|---|---|---|
| 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |