I want to generate a matrix of css selector in the form of .cX.rY selectors for a grid of something like 10 x 10. But I'm not seeing how I can do this less (I'm pretty new to .less). I'm using DotLess too, so perhaps there are some built-in limitations with that; I don't know for sure on that front.
@col-width: -24px;
@row-width: -24px;
.img-pos(@col, @row) {
background-position:
(((@col - 1) * @col-width) - 1)
(((@row - 1) * @row-width) - 1);
}
.c2.r1 { .img-pos(2, 1); }
.c2.r2 { .img-pos(2, 2); }
.c2.r3 { .img-pos(2, 3); }
.c2.r4 { .img-pos(2, 4); }
.c2.r5 { .img-pos(2, 5); }
.c2.r6 { .img-pos(2, 6); }
.c2.r7 { .img-pos(2, 7); }
...
...
.cX.rY { .img-pos(2, 7); }
Is this possible? If so, how?
Here is some code that allows you set the max columns and rows, as well as optionally set the start column and row number (default: 1), and optionally set the class indicator for them (defaults to "c" and "r"). It uses a looping technique in LESS to auto generate the code.
LESS Code
CSS Output