2014-02-21 16 views
0

所以我的代码是有一个重大的问题,我似乎无法来解决这个问题。LESS变量:是有这种类型可能

每当我减去行81有问题。
我怎样才能解决这个问题?

@max-columns: 2; 
@column-1-width-min: 30; 
@column-2-width-min: 40; 

.loop-column(@index) when (@index > 0) { 

    @max-minus-1a: "@{[email protected]{index}-width-min}"; 
    @max-minus-1b: @max-minus-1a - 1; // problem child 

    @min: ~"min-width: @{[email protected]{index}-width-min}"; 
    @max: ~"max-width: @{max-minus-1b}"; 

    @media (@min) and (@max) { 

    [data-deckgrid="card"]::before { 
     content: "@{index} [email protected]{index}"; 
    } 
    } 

    .loop-column(@index - 1); 
} 

.loop-column(@max-columns); 
+0

看的非常类似的问题,我今天回答:http://stackoverflow.com/q/21932983/2712740 –

回答

2

除了方法,你可以在this SO answer找到(如我上面我的评论已经提到),我觉得整个片段可以简化为像(以下1.5.x版或更高版本):

@column-widths: 30, 40, 55, 500; // etc. 

.loop-column(@index) when (@index > 0) { 
    .loop-column(@index - 1); 

    @min: extract(@column-widths, @index); 
    @max: (extract(@column-widths, @index + 1) - 1); 

    @media (min-width: @min) and (max-width: @max) { 
     [data-deckgrid="card"]::before { 
      content: "@{index} [email protected]{index}"; 
     } 
    } 
} 

.loop-column(length(@column-widths) - 1); 

与下面的CSS结果:

@media (min-width: 30) and (max-width: 39) { 
    [data-deckgrid="card"]::before { 
    content: "1 .column.card-column-1"; 
    } 
} 
@media (min-width: 40) and (max-width: 54) { 
    [data-deckgrid="card"]::before { 
    content: "2 .column.card-column-2"; 
    } 
} 
@media (min-width: 55) and (max-width: 499) { 
    [data-deckgrid="card"]::before { 
    content: "3 .column.card-column-3"; 
    } 
} 

即不需要通过“索引变量名”模拟阵列,因为可以直接使用阵列(减阵列仅仅是一个逗号或空格分隔值列表中,例如@padding: 1 2 3 4;)。

相关问题