SCSS 选择器选择子元素最后一个孩子:多种写法详解
在 SCSS 中,选择器选择子元素的最后一个孩子可以使用以下几种写法:
- 使用 ':nth-last-child()' 伪类选择器:
.parent {
&:nth-last-child(1) {
// 样式
}
}
- 使用 ':last-child' 伪类选择器:
.parent {
&:last-child {
// 样式
}
}
- 使用 ':nth-child()' 伪类选择器并结合 ':nth-last-child()' 伪类选择器:
.parent {
&:nth-child(n):nth-last-child(1) {
// 样式
}
}
这些写法都可以选择父元素的最后一个子元素。请根据您的需求选择适合的写法。
原文地址: https://www.cveoy.top/t/topic/qktU 著作权归作者所有。请勿转载和采集!