| Start |
|---|
| A Basic Implementation What's an image sprite? An image sprite is a single asset located within an image sprite sheet. An image sprite sheet is an image file that contains more than one asset that can be extracted from it. For example: The image above is an image sprite sheet, and each one of those stars is a sprite within the sprite sheet. These sprite sheets are useful because they improve performance by reducing the number of HTTP requests a browser might have to make. So how do you implement one? Here's some example code. HTML CSS By using setting the sprite's width and height and by using the background-position property in CSS (with an x and y value) you can easily extract sprites from a sprite sheet using CSS. Syntaxbackground: url("sprite-image.png"); background-position: -20px 50px; background: url("sprite-image.png") -20px 50px; RemarksFor some use cases, sprites are slowly falling out of favor, being replaced by icon webfonts or SVG images (opens new window). |
Read Article
https://develop.horje.com/learn/1434/reference