CSS :last-child 伪类
示例
为作为其父元素最后一个子元素的 <p> 元素指定背景颜色。也为作为其父元素最后一个子元素的 <li> 元素指定背景颜色。
p:last-child {
background-color: yellow;
}
li:last-child {
background-color: yellow;
}
自己动手试一试 »
定义和用法
:last-child
伪类匹配其父元素的最后一个子元素。
提示: p:last-child 等同于 p:nth-last-child(1)。
版本 | CSS3 |
---|
浏览器支持
表中数字表示该伪类完全支持的第一个浏览器版本。
伪类 | |||||
---|---|---|---|---|---|
:last-child | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
CSS 语法
相关页面
CSS 参考::last-of-type