I am curently using LESS. Since I use CSS sprites, I wonder if LESS support this kind of syntax:
icon{x}{
background-position:-10px -10*{x}px;
}
Since I have to create this CSS style:
icon1{
background-position:-10px -10px;
}
icon2{
background-position:-10px -20px;
}
icon3{
background-position:-10px -30px;
}
.................
Is it possible ?
Unfortunately, I think it’s not. LESS is a compiled language and doesn’t support (yet ?) iteration control structures like
while()orfor().To begin an answer, I would write the following HTML code :
With the following LESS code :
Which would result as the following CSS code :
But as you can see, this code is dynamic for only one element by page, due to the
[x]on the result ofgetElementsByClassName. Maybe there is an additional trick that I’m missing there, though.Alternative solution
Maybe could you just use Javascript :
Which results in the following: