An Intro to CSS Sprites
What is it?
CSS Sprites are an interesting method to cut down on both a website’s initial construction phase and the bulkiness of excessive loading time. Instead of creating a separate image file for each graphic used on a website, several can be combined in one with only the appropriate element showing based on specific positions defined in the CSS.
Why Is It Important?
Websites with lots of graphic elements can benefit from the use of sprites on both the developers’ end and the users’ end. It’s definitely a win-win situation when the developer can cut back on the tedious work of image slicing and the users have a faster web page load time. The old train of thought was that by cutting up the images into a bunch of smaller pieces that it would be faster and easier to load. Unfortunately, that was not the case. By creating more files than necessary for a browser to retrieve from the server, it actually creates a longer loading time. CSS sprites also replaces the need for JavaScript rollovers and image preloading – all in all, a very helpful solution.
The Basic Theory
Let’s say that you have a menu of 5 image links that when you hover over each individual button you want the respective image to swap out. The old way would be to create 10 separate images and link to each one. While nothing is technically wrong with this method, that’s 10 separate server requests and lots of image slicing. Let’s see an example button.
In Action
Since this sprite only has two states for one button, when used it is far easier to define the CSS. Something along the lines of the following would work just fine:
#nav a.button {background: url(samplebutton.gif) top; display: block; width: 171px; height:49px}
#nav a.button:hover {background: url(samplebutton.gif) bottom; display: block; width: 171px; height:49px}
</style>
More Explanation
With a more complicated sprite, the theory is just the same. Instead of using the “top” and “bottom” attribute to define the correct positions of the on/off states, you simply have to use more precise positioning. If you’re using a sprite with four images, using “top left”, ” top right”, “bottom left” and “bottom right” will suffice. However, the larger the sprite grows, the more specifics the dimensions will have to be — usually in pixels — to define the position of a sprite that holds more than 4 images. For the example button, using pixels to define the position looks something like the following:
#nav a.button {background: url(samplebutton.gif) 0px 0px; display: block; width: 171px; height:49px}
#nav a.button:hover {background: url(samplebutton.gif) 0px 49px; display: block; width: 171px; height:49px}
</style>
The first positioning attribute defines the x-axis coordinates of the image and the second defines the y-axis coordinates, both from the top left corner. Since both images are 49 pixels tall stacked on top of each other, the second image’s definitions are the same x-axis position but pushed 49 pixels down to call the rollover image in exactly the right spot.
And that’s it! A brief explanation that can take you onto the road of CSS sprite creation so long as your graphing and plotting skills are good.





I guess “piss poor” wasn’t an option. Not only does 07 limit what we as designers can do from a creative standpoint but it creates a lot of angst with our clients who don’t want to pay for the additional time required to properly test and troubleshoot.

