codecamp

CSS3 :last-child 选择器

CSS3 :last-child 选择器

CSS完整选择器完整CSS选择器参考手册

定义和用法

:last-child选择器用来匹配父元素中最后一个子元素。

提示: p:last-child等同于p:nth-last-child(1)。


Examples

实例

实例

指定父元素中最后一个p元素的背景色:

p:last-child
{
  background:#ff0000;
}

尝试一下 »

浏览器支持

表格中的数字表示支持该属性的第一个浏览器版本号。

选择器     
:last-child4.09.03.53.29.6

CSS完整选择器完整CSS选择器参考手册

CSS :lang() 选择器
CSS3 :last-of-type 选择器
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }