I have a list of strings as such in LESS: @flag-codes: "Albania" "al", "United States" "us", ...; I created a loop in LESS which I have achieved by using:
.flag-classes(@flags; @index: 1) when (@index <= length(@flag-codes)) {
@flag: extract(@flags, @index);
@name: extract(@flag, 1);
@code: e(extract(@flag, 2));
// X Y
.flag-@{code} {
background-position: (24 * mod(@index, 8)) mod(@index, 16);
}
.flag-classes(@flags; (@index + 1));
}
.flag-classes(@flag-codes);
As you can see I am also trying to generate a background-position property which will have the values based on the loop index, but that only on the x axis.
The image used is a PNG sprite that has a collection of sprites organised in a matrix (8 columns and 16 rows).
I have managed to figure out how to set the x property which will always have @index % 8, but on the y axis it will have to start from 1 to 16 and keep the 1 for 8 times (as many columns as we have) and after each 8 increase with a unit.
Is something as described above possible to do, and if so how would I do it?