Specific Solution in This Case
I recommend making a master mixin to generate what you need, as you need it. Here is a solution that works with your current version of LESS 1.3.1:
LESS
.make-icon-16(@form: all) {
background: url('/Content/images/app/icons-16.png') no-repeat top left;
width: 16px;
height: 16px;
@about: 0px 0px;
@add: 0px -16px;
@add2: 0px -32px;
.makePositioning() when (@form = all) {
&.about { background-position: @about; }
&.add { background-position: @add; }
&.add2 { background-position: @add2; }
}
.makePositioning() when (@form = about) {
background-position: @about;
}
.makePositioning() when (@form = add) {
background-position: @add;
}
.makePositioning() when (@form = add2) {
background-position: @about;
}
.makePositioning();
}
//to generate icon classes
.icon-16 {
.make-icon-16;
}
//to include as you want in your class
.myClass {
.make-icon-16(about);
}
CSS Output
.icon-16 {
background: url('/Content/images/app/icons-16.png') no-repeat top left;
width: 16px;
height: 16px;
}
.icon-16.about {
background-position: 0px 0px;
}
.icon-16.add {
background-position: 0px -16px;
}
.icon-16.add2 {
background-position: 0px -32px;
}
.myClass {
background: url('/Content/images/app/icons-16.png') no-repeat top left;
width: 16px;
height: 16px;
background-position: 0px 0px;
}
If you don't need or want the actual .icon-16
classes, skip the step that makes those as it is not necessary for you to do that.
More General Solution?
If your icons have the right logic to them, then this can be more generalized to accommodate any size icon.
LESS
.make-icon(@form: all, @size: 16) {
background: url('/Content/images/app/icons-@{size}.png') no-repeat top left;
width: @size*1px;
height: @size*1px;
@about: 0px 0px;
@add: 0px (@size*-1px);
@add2: 0px (@size*-2px);
.makePositioning() when (@form = all) {
&.about { background-position: @about; }
&.add { background-position: @add; }
&.add2 { background-position: @add2; }
}
.makePositioning() when (@form = about) {
background-position: @about;
}
.makePositioning() when (@form = add) {
background-position: @add;
}
.makePositioning() when (@form = add2) {
background-position: @about;
}
.makePositioning();
}
//to generate icon classes for 32px size
.icon-32 {
.make-icon(all, 32);
}
CSS Output
.icon-32 {
background: url('/Content/images/app/icons-32.png') no-repeat top left;
width: 32px;
height: 32px;
}
.icon-32.about {
background-position: 0px 0px;
}
.icon-32.add {
background-position: 0px -32px;
}
.icon-32.add2 {
background-position: 0px -64px;
}