LESS image sprite mixin for maintaining sprite definitions in a single location with pseudo-class support.
@import 'sprite.less';
Example is based on a 16 px wide, horizontal sprite.
.mySprite(@item) {
/* Define name and position in sprite */
@items: '{"twitter": 1, "facebook": 2, "google": 3, "skype": 4 }';
.sprite('../images/mySprite.png', 16px, @item, @items);
}
.mySprite(@item) {
.sprite('../images/mySprite.png', 16px, @item);
}
#socialNetwork li#twitter a { .mySprite('twitter') }
#socialNetwork li#facebook a { .mySprite('facebook') }
...
#socialNetwork li#twitter a { .mySprite(1) }
#socialNetwork li#facebook a { .mySprite(2) }
...
#socialNetwork li#twitter a{background:url("../images/mySprite.png") 0px 0px no-repeat;background-position:0 0px;}
#socialNetwork li#facebook a{background:url("../images/mySprite.png") 0px 0px no-repeat;background-position:0 -16px;}