首页 > 解决方案 > 在这种情况下,有没有更好的方法来使用嵌套的 SASS 和选择器?

问题描述

我需要选择一个元素的子元素,但它基于父元素的 :last-of-type 。

我试过了:

&:last-of-type {
  &__content {
    border-bottom: 0;
  }
}

由于 SASS 的构造方式,这不起作用。

我最终得到:

.assignment-selection {
  &__list-item {
    &__content {
      border-bottom: 1px solid;
    }
    &:last-of-type {
      .assignment-selection {
        &__list-item {
          &__content {
            border-bottom: 0;
          }
        }
      }
    }
  }
}

有没有更好/更有效的方法来写这个?

标签: csssass

解决方案


这应该这样做

&:last-of-type > &__content {
  border-bottom: 0;
}

推荐阅读