有以下几种写法可以选择子元素的最后一个孩子:

  1. 使用 ':last-child' 伪类选择器:
.parent > :last-child {
  /* 样式 */
}
  1. 使用 ':last-of-type' 伪类选择器:
.parent > :last-of-type {
  /* 样式 */
}
  1. 使用 ':nth-last-child' 伪类选择器:
.parent > :nth-last-child(1) {
  /* 样式 */
}
  1. 使用 ':nth-last-of-type' 伪类选择器:
.parent > :nth-last-of-type(1) {
  /* 样式 */
}

这些写法都可以选择父元素下的子元素中的最后一个孩子元素,并对其应用样式。

SCSS 选择器:如何选择子元素的最后一个孩子

原文地址: https://www.cveoy.top/t/topic/qktS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录