I like your @sandeep and @ hatake-kakashi methods. A couple of possible improvements (although perhaps beyond the scope of the question). Try to structure your list and html as such:
<style> ul.sprites {width:somevalue;} ul.sprites li {float:left;} ul.sprites li a { display:block; width:30px; height:30px; background: url('..images/spritesSheet.png') 0 0 no-repeat; text-indent: -9999em overflow: hidden; text-align: left; } ul.sprites a.spriteName1 {background-position:xy;} ul.sprites a.spriteName1:hover {background-position:xy;} ul.sprites a.spriteName2 {background-position:xy;} ul.sprites a.spriteName2:hover {background-position:xy;} </style> <html> <ul class="sprites"> <li><a class="spriteName1" href="#">link1</a></li> <li><a class="spriteName2" href="#">link2</a></li> </ul> </html>
Thus, the cascade works for you, and all links in this list can get the sprite style without redundant class names. And you allow your parent elements to handle positioning. At least I think that's right. Apologies for the syntax and pseudo-code, since I wrote it as if quickly and dirty.
source share