0%
使用递归调用来循环
less 编译前
1 2 3 4 5 6 7 8 9 10 11 12
| .loop(@n) when (@n > 0) { div:nth-of-type(@{n}){ width: (@n*10px); height: 40px; background: red; margin: 10px; font-size: 12px; } .loop(@n - 1); }
.loop(5);
|
css 编译后
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| div:nth-of-type(5) { width: 50px; height: 40px; background: red; margin: 10px; font-size: 12px; } div:nth-of-type(4) { width: 40px; height: 40px; background: red; margin: 10px; font-size: 12px; } div:nth-of-type(3) { width: 30px; height: 40px; background: red; margin: 10px; font-size: 12px; } div:nth-of-type(2) { width: 20px; height: 40px; background: red; margin: 10px; font-size: 12px; } div:nth-of-type(1) { width: 10px; height: 40px; background: red; margin: 10px; font-size: 12px; }
|