概述

:last-child CSS 伪类 代表父元素的最后一个子元素。

语法

:last-child

示例

HTML 内容

<ul>
  <li>此元素背景色不是lime</li>
  <li>我的也不是lime。</li>
  <li>我的才是lime! :)</li>
</ul>

CSS 内容

li:last-child {
  background-color: lime;
}

规范

Specification Status Comment
Selectors Level 4
:last-child
Working Draft No change
Selectors Level 3
:last-child
Recommendation Initial definition

浏览器支持

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
:last-childChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 9Opera Full support 9.5Safari Full support 3.2WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support 12Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 3.2Samsung Internet Android Full support Yes
Matches elements with no parentChrome Full support 57Edge No support NoFirefox Full support 52IE No support NoOpera Full support 44Safari No support NoWebView Android Full support 57Chrome Android Full support 57Edge Mobile No support NoFirefox Android Full support 52Opera Android Full support 43Safari iOS No support NoSamsung Internet Android Full support 7.0

Legend

Full support  
Full support
No support  
No support

相关链接

文档标签和贡献者

此页面的贡献者: mdnwebdocs-bot, Ritr, FrontENG, AlexChao
最后编辑者: mdnwebdocs-bot,