需要循环遍历变量集

时间:2014-09-02 02:56:59

标签: css colors less less.js

需要将@color-1@color-2@color-3,...放在@color-@{i}的循环中。我该怎么办呢?

@color-0: rgb(200, 20, 20);
@color-1: ...;
@color-2: ...;
// ...

.generate-headers(5);

.generate-headers( @n, @i: 0 ) when ( @i =< @n ) {
  .widget-header-@{i} {
    width: (@i * 100% / @n);
    background-color: @color-@{i};
    color: overlay( @color-@{i}, @white );
  }
  .generate-headers(@n, (@i + 1));
}

1 个答案:

答案 0 :(得分:1)

找到了一种方法:

    @color: "color-@{i}";
    background-color: @@color;