functions-each.less 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. @selectors: blue, green, red;
  2. @list: a b c d;
  3. each(@selectors, {
  4. .sel-@{value} {
  5. a: b;
  6. }
  7. });
  8. .each {
  9. each(@list, {
  10. index+: @index;
  11. item@{index}: @value;
  12. });
  13. // nested each
  14. each(10px 15px, 20px 25px; {
  15. // demonstrates nesting of each()
  16. each(@value; #(@v, @k, @i) {
  17. nest-@{i}-@{index}: @v @k;
  18. });
  19. });
  20. // nested anonymous mixin
  21. .nest-anon {
  22. each(a b, .(@v;@i) {
  23. each(c d, .(@vv;@ii) {
  24. nest-@{i}-@{ii}: @v @vv;
  25. });
  26. });
  27. }
  28. // vector math
  29. each(1 2 3 4, {
  30. padding+_: (@value * 10px);
  31. });
  32. }
  33. @set: {
  34. one: blue;
  35. // skip comments
  36. two: green;
  37. /** and these
  38. */
  39. three: red; //and this
  40. }
  41. .set {
  42. each(@set, {
  43. @{key}: @value;
  44. });
  45. }
  46. .set-2() {
  47. one: blue;
  48. two: green;
  49. three: red;
  50. }
  51. .set-2 {
  52. each(.set-2(), .(@v, @k, @i) {
  53. @{k}-@{i}: @v;
  54. });
  55. }
  56. .pick(@a) when (@a = 4) {
  57. val3: @a;
  58. }
  59. .single {
  60. each(true, {
  61. val: @value;
  62. });
  63. @exp: 1 + 1;
  64. each(@exp, {
  65. val2: @value;
  66. });
  67. each(1 2 3 4, {
  68. .pick(@value);
  69. });
  70. }
  71. @columns: range(4);
  72. .column-list {
  73. list: @columns;
  74. }
  75. each(@columns, .(@val) {
  76. .col-@{val} {
  77. width: (100% / length(@columns));
  78. }
  79. });
  80. each(range(10px, 30px, 10px), .(@val, @index) {
  81. .row-@{index} {
  82. width: @val;
  83. }
  84. });
  85. @list: a b c d;
  86. .box {
  87. each(@list, {
  88. -less-log: extract(@list, @index);
  89. })
  90. }
  91. // https://github.com/less/less.js/issues/3325
  92. @color-schemes: {
  93. @primary: {
  94. @color: blue;
  95. }
  96. @secondary: {
  97. @color: red;
  98. }
  99. }
  100. .test {
  101. each(primary secondary, .(@color-name) {
  102. @scheme: @color-schemes[@@color-name]; // e.g. @color-name = primary
  103. color: @scheme[@color];
  104. });
  105. }
  106. @one: {
  107. @two: {
  108. foo: red;
  109. bar: blue;
  110. };
  111. };
  112. each(@one[@two], {
  113. .@{key} {
  114. content: @value;
  115. }
  116. });