SCSS 选择最后一个子元素:四种常用方法
在 SCSS 中,可以使用以下多种方式选择最后一个子元素:
- 使用
:last-child伪类选择器:
.parent {
> div:last-child {
// 样式
}
}
- 使用
:nth-last-child()伪类选择器,指定参数为1:
.parent {
> div:nth-last-child(1) {
// 样式
}
}
- 使用
:last-of-type伪类选择器:
.parent {
> div:last-of-type {
// 样式
}
}
- 使用
:nth-last-of-type()伪类选择器,指定参数为1:
.parent {
> div:nth-last-of-type(1) {
// 样式
}
}
以上是常用的几种选择最后一个子元素的方式,根据具体情况选择适合的写法。
原文地址: https://www.cveoy.top/t/topic/qkuq 著作权归作者所有。请勿转载和采集!