Skip to content

Instantly share code, notes, and snippets.

@anovsiradj
Last active October 7, 2019 02:24
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 anovsiradj/3de6c00e85480a2e8b4f4dd2db0887e6 to your computer and use it in GitHub Desktop.
Save anovsiradj/3de6c00e85480a2e8b4f4dd2db0887e6 to your computer and use it in GitHub Desktop.
LESS: Loop dynamic selector rule (CSS)
.looper(@class, @property, @unit: px, @min: 0, @max: 10, @step: 1) {
.loop(@i) when (@i <= @max) {
@cls: e(replace(@class, '\*', @i, 'g'));
@{cls} {
@{property}: unit(@i, @unit);
}
.loop(@i + @step);
}
.loop(@min);
}
/*
Usage:
.looper('.w-*', width, px); ===> .w-0 {width: 0px} ... .w-10 {width: 10px}
.looper('.h-*,', height, %, 0, 100, 10); ===> .h-0 {height: 0%} ... .h-100 {height: 100%}
Only support single rule.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment