--- title: ':last-child' slug: 'Web/CSS/:last-child' translation_of: 'Web/CSS/:last-child' ---
:last-child
CSS 伪类 代表父元素的最后一个子元素。
<ul> <li>此元素背景色不是lime</li> <li>我的也不是lime。</li> <li>我的才是lime! :)</li> </ul>
li:last-child { background-color: lime; }
{{EmbedLiveSample('%E7%A4%BA%E4%BE%8B', '100%', 100)}}
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS4 Selectors', '#last-child', ':last-child')}} | {{Spec2('CSS4 Selectors')}} | No change |
{{SpecName('CSS3 Selectors', '#last-child', ':last-child')}} | {{Spec2('CSS3 Selectors')}} | Initial definition |
{{Compat("css.selectors.last-child")}}