导航
×
   ❮   
HTML CSS JavaScript PHP Go Sass W3C Colors ECMS

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 语法

:last-child {
  CSS 声明;

相关页面

CSS 参考::last-of-type


Copyright ©2020-2026 freew3c.com All Rights Reserved 提供的内容仅用于学习和测试,不保证内容的正确性。