概述

: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 AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 1Edge Full support YesFirefox 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 YesFirefox Android Full support 4Opera Android Full support 10Safari iOS Full support 3.2Samsung Internet Android Full support Yes
Matches elements with no parentChrome Full support 57Edge ? Firefox Full support 52IE ? Opera Full support 44Safari ? WebView Android Full support 57Chrome Android Full support 57Edge Mobile ? Firefox Android Full support 52Opera Android Full support 44Safari iOS ? Samsung Internet Android Full support 7.0

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

相关链接

文档标签和贡献者

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