Last active
October 7, 2019 09:37
-
-
Save danro/6196732 to your computer and use it in GitHub Desktop.
LESS css loop example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.loop (0) {} | |
.loop (@index) when (@index > 0) { | |
.classname-@{index} { | |
top: @index * 1px; | |
} | |
.loop (@index - 1); | |
} | |
#example { | |
.loop(5); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#example .classname-5 { | |
top: 5px; | |
} | |
#example .classname-4 { | |
top: 4px; | |
} | |
#example .classname-3 { | |
top: 3px; | |
} | |
#example .classname-2 { | |
top: 2px; | |
} | |
#example .classname-1 { | |
top: 1px; | |
} |
@max-grid-items : 20;
.grid-row-loop (0) {}
.grid-row-loop (@index) when (@index > 0) {
@nextIndex : (@index * 2);
@prevIndex : (@nextIndex - 1);
&:nth-child(@{prevIndex}) {
grid-row: @index;
}
&:nth-child(@{nextIndex}) {
grid-row: @index;
}
.grid-row-loop (@index - 1);
}
.grid-row-loop (@max-grid-items);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, can we multiply the index for any value?
In SCSS we can do this:
You can check here the output http://www.sassmeister.com/
Now i can say that my class-(index*5), can we do this with LESS?
Best regards, Mário Silva.