如何用更少的语法生成更少的语法?

时间:2015-06-07 13:11:12

标签: less

我想生成一个包含所有按钮样式的公共类,它看起来像这样

 .commonButton {
      .button1;
      .button2;
      .button3;
      .
      .button15;
  }

那么如何更少地生成这种语法?我试过的是这样的

.loopingClass(@index) when (@index > 0) {   
  .button@{index}; // this will give syntax error
  .loopingClass(@index - 1);
};
.loopingClass(15);

1 个答案:

答案 0 :(得分:0)

难道你不能只为所有按钮的所有常用属性创建1个类,然后是一系列单独的类,它们只是覆盖了差异化的功能吗? e.g。

.white {color: white;}
.blue {color: blue;}
.green {color: green;}
.ctralign {text-align: center;}

等等。然后你的HTML将是:

<img class="button white ctralign"...