SASS可以合并属性吗?

时间:2012-10-24 11:44:09

标签: sass

也许更好的问题是,是否有更有效的方式来覆盖mixin的部分?

这篇SCSS:

@mixin button {
  .button {
    background-color: red;
    color: white;
  }
}

.container {
  @include button;
  .button {
    background-color: green;
  }
}

汇编为:

.container .button {
  background-color: red;
  color: white;
}
.container .button {
  background-color: green;
}

我希望它能编译成:

.container .button {
  background-color: green;
  color: white;
}

1 个答案:

答案 0 :(得分:3)

将参数传递给mixin:

@mixin button($color: red) {
    background-color: $color;
    color: white;
}

.container {
  .button {
    @include button(green);
  }
}