// ............................................................
// for.less file
// https://github.com/seven-phases-max/less.curious/blob/master/articles/generic-for.md
.for(@i, @n) {.-each(@i)}
.for(@n) when (isnumber(@n)) {.for(1, @n)}
.for(@i, @n) when not (@i = @n) {
.for((@i + (@n - @i) / abs(@n - @i)), @n);
}
// ............................................................
// .for-each
.for(@array) when (default()) {.for-impl_(length(@array))}
.for-impl_(@i) when (@i > 1) {.for-impl_((@i - 1))}
.for-impl_(@i) when (@i > 0) {.-each(extract(@array, @i))}
// Usage
// ............................................................
@import "for";
@array: alice black, bob orange;
.classeCSS {
.for(@array); .-each(@value) {
@name: extract(@value, 1);
&@{name} {
background-color: extract(@value, 2);
}
}
}
foreach mixin with LESS
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.