Joe.wang
Joe.wang

Reputation: 11793

output % with less

All, I have some code do a loop in less. But if I change the px to '%', the less can't compile the less file .How can i make it ? thanks.

@iterations: 100;

// helper class, will never show up in resulting css
// will be called as long the index is above 0
.loopingClass (@index) when (@index > 0) {

    // create the actual css selector, example will result in
    // .myclass_30, .myclass_28, .... , .myclass_1
    (~".span@{index}") {
        // your resulting css
        width: @index px;//can not change px to % , please help me.
    }

    // next iteration
    .loopingClass(@index - 1);
}

// end the loop when index is 0
.loopingClass (0) {}

// "call" the loopingClass the first time with highest value
.loopingClass (@iterations);

Upvotes: 0

Views: 57

Answers (2)

ScottS
ScottS

Reputation: 72261

Glad you found a solution. Here is another way to do it:

width: @index*1%

Upvotes: 1

Joe.wang
Joe.wang

Reputation: 11793

I found it !

width: percentage(@index *0.01);

thanks

Upvotes: 1

Related Questions