css - 您如何编写供多个类使用的 LESS 规则?

标签 css less less-mixins

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

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}

我试过了,它只是杀死了 LESS。

最佳答案

您想使用 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();
}

关于css - 您如何编写供多个类使用的 LESS 规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28981979/

相关文章:

css - 是否可以使用 Twitter Bootstrap 或 CSS 选择器淡出 Devise 警报?

javascript - 基金会 5 : Styling my img size to the be 100% of a div

css - 内部服务器错误 500.19::.less mimeMap

css - LESSCSS 转义过滤器

css - LESSCSS - 使用计算和返回值

css - "+"在 CSS 中是什么意思?

javascript - 只改变一个 div 的 z-index 而不是它的每个 child

html - Bootstrap 列内容显示对齐到顶部

css - 从像素转换为 em

css - 通过 less 生成 CSS 组