0

假设我们需要几个不同的类来使用以下内容:

color:#ccf;
background-color:#fcc;
font-size:0.7em;

我们如何在 LESS 中进行设置?

这些类不能相互使用,因此将它们设置在逗号分隔的列表中(.note、.product、.restricted{ })不是解决方案。

我们需要类似的东西:

@myClass{
    color:#ccf;
    background-color:#fcc;
    font-size:0.7em;
}

.note{@myClass}
.product{@myClass}
.restricted{@myClass}

我试过这个,它只会杀死更少。

4

1 回答 1

4

您想使用 LESS mixins

.mixin-name() { //mixin which can be used by any selector
  color:#ccf;
  background-color:#fcc;
  font-size:0.7em;
}

.note {
  .mixin-name();
}

.product {
  .mixin-name();
}

.restricted {
  .mixin-name();
}
于 2015-03-11T08:53:29.063 回答