图:淘宝网中的精灵图
<!DOCTYPE html> <html> <head> <style> ul li { float: left; width: 30px; height: 30px; list-style: none; margin: 5px; border: 1px solid #CCC; border-radius: 6px; } ul li:nth-child(1){ background: url(./sprite.png) no-repeat 4px 1px; } ul li:nth-child(2){ background: url(./sprite.png) no-repeat -38px 1px; } ul li:nth-child(3){ background: url(./sprite.png) no-repeat -81px 3px; } ul li:nth-child(4){ background: url(./sprite.png) no-repeat -123px 2px; } ul li:nth-child(5){ background: url(./sprite.png) no-repeat -171px 0px; } ul li:nth-child(6){ background: url(./sprite.png) no-repeat -214px 2px; } ul li:nth-child(7){ background: url(./sprite.png) no-repeat -267px 1px; } ul li:nth-child(8){ background: url(./sprite.png) no-repeat 2px -36px; } </style> </head> <body> <ul> <li></li><li></li> <li></li><li></li> <li></li><li></li> <li></li><li></li> </ul> </body> </html>运行结果如下:
图:精灵图演示
本文链接:http://task.lmcjl.com/news/14599.html