9

而不是这样写:

.class-one .class-two h2, .class-one .class-two h3, .class-one .class-two h4,
.different-class-one .different-class-two h2, .different-class-one .different-class-two h3, .different-class-one .different-class-two h4
.another-class-one .another-class-two h2, .another-class-one .another-class-two h3, .another-class-one .another-class-two h4
{
  background-color: @orange;
}

有没有办法将一组类定义为主选择器,然后更改最终选择器?

就像是:

.class-one .class-two h2 / h3 / h4,
.different-class-one .different-class-two h2 / h3 / h4,
.another-class-one .another-class-two h2 / h3 / h4
{
  background-color: @orange;
}
4

1 回答 1

14

使用混合

.header-template() {
    h2, h3, h4 {
        background-color: @orange;
    }
}

.class-one .class-two,
.different-class-one .different-class-two,
.another-class-one .another-class-two {
    .header-template();
}

(声明@orange变量后,前面的编译成)

.class-one .class-two h2,
.different-class-one .different-class-two h2,
.another-class-one .another-class-two h2,
.class-one .class-two h3,
.different-class-one .different-class-two h3,
.another-class-one .another-class-two h3,
.class-one .class-two h4,
.different-class-one .different-class-two h4,
.another-class-one .another-class-two h4 {
  background-color: #ffa500;
}
于 2013-06-03T08:07:55.007 回答