不是最后 child mixin SASS

Not last child mixin SASS

这个可以转吗:

.redstripe p:not(last-child) {
  border-bottom:1px solid red;
}

进入 mixin 以便我可以将它应用于任何元素并为其分配一个 child 标记,例如:

@mixin redstripe (this.$children):not(last-child) {
  border-bottom:1px solid red;
}

然后申请:

div {
  @include redstripe(p);
}

实现这个的正确方法是什么?

这是您所描述的通用混入。

DEMO

@mixin not-last-child($selector) {
  & #{$selector}:not(:last-child) {
    @content;
  }
}

我们可以传递一个选择器字符串给它使用。

SCSS:

.thing {
  @include not-last-child('p') {
    color: red;
  }
}

CSS:

.thing p:not(:last-child) {
  color: red;
}

Sass Documentation