Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 选择最后一个直接子级_Css - Fatal编程技术网

Css 选择最后一个直接子级

Css 选择最后一个直接子级,css,Css,我正在尝试选择一组元素的最后一个直接子元素,如中的最后一个.container: 问题是它没有应用样式。以下是我尝试使用的代码: #allthecontent > .container:last-child { overflow: auto; padding-bottom: 150px; } 提前谢谢 虽然不可能匹配上次出现的.container,除非它恰好是其父对象的最后一个子对象,但可以使用第n个最后一个子对象选择器指定范围 #allthecontent > ​.c

我正在尝试选择一组元素的最后一个直接子元素,如中的最后一个.container:

问题是它没有应用样式。以下是我尝试使用的代码:

#allthecontent  > .container:last-child {
  overflow: auto;
  padding-bottom: 150px;
}

提前谢谢

虽然不可能匹配上次出现的
.container
,除非它恰好是其父对象的最后一个子对象,但可以使用第n个最后一个子对象选择器指定范围

#allthecontent > ​.container:nth-last-child(-n + 2) {
  overflow: auto;
  padding-bottom: 150px;
}

这将使任何元素与父元素最后2个元素中出现的
容器
类相匹配。但是,此选择器在IE8及以下版本中不起作用。

它的工作方式与此不同。您的选择器将一个元素与
容器
类匹配,该类恰好是其父级的最后一个子级。啊,我明白了。对不起,我太傻了。