Skip to content

Instantly share code, notes, and snippets.

@basecss
Created January 18, 2014 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basecss/8493476 to your computer and use it in GitHub Desktop.
Save basecss/8493476 to your computer and use it in GitHub Desktop.
loop for less
.loop(@index) when (@index > 0) {
selector:nth-child(@index) {
property: @index * 1px; // use @index
}
.loop(@index - 1); // 递归
}
// Example
.loop(@index) when (@index > 0) {
ul li:nth-child(@index) {
border: @index * 1px; // use @index
}
.loop(@index - 1); // 递归
}
.loop(5);
// output
ul li:nth-child(5) {
border: 5px;
}
ul li:nth-child(4) {
border: 4px;
}
ul li:nth-child(3) {
border: 3px;
}
ul li:nth-child(2) {
border: 2px;
}
ul li:nth-child(1) {
border: 1px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment