Last Updated: February 25, 2016
·
757
· juanbrujo

Looping in LESS

Looping in LESS:

.loop(@index) when (@index > 0){
  selector:nth-child(@{index}) { 
    property: @index * 1px; 
  }
  .loop(@index - 1);
}
.loop(0){}
.loop(3); // loop 3 times

Renders in CSS:

selector:nth-child(4) {
  property: 4px;
}
selector:nth-child(3) {
  property: 3px;
}
selector:nth-child(2) {
  property: 2px;
}
selector:nth-child(1) {
  property: 1px;
}