How to generate CSS with loop in less

前端 未结 4 1666
执念已碎
执念已碎 2020-12-05 04:33

I am not familiar with Less. In my understanding, I think Less can transform the less format file to standard css file(if

4条回答
  •  抹茶落季
    2020-12-05 04:58

    It is impossible to do within given methods.

    But possible like this:

    .loopingClass (@index) when (@index > 0){
      .span_@{index}{
        width: @index px;
      }
      .loopingClass(@index - 1);
    }
    .loopingClass(5);
    

    Resilt will be like this:

    .span_100 {
      width: 100 px;
    }
    .span_99 {
      width: 99 px;
    }
    .span_98 {
      width: 98 px;
    }
    .span_97 {
      width: 97 px;
    }
    .span_96 {
      width: 96 px;
    }
    .span_95 {
      width: 95 px;
    }
    
    and e.t.c.
    

提交回复
热议问题