CSS Sprites technique used on haidabo.com

November 17th, 2009

After being inspired the other day, I decided it was time to design a new per­sonal site. I’ve owned the domain haidabo.com for a while, but wasn’t really sure what to do with it until now. So, it has become a place to show­case my var­i­ous projects as well as aggre­gate RSS feeds from all of my sites with dynam­i­cally updated content.

Screenshot of haidabo.com

While I was design­ing haidabo.com, I used a tech­nique that I’d like to share called CSS Sprites. This wasn’t my first time using sprites, but it was the first time I planned on using them to this extent. My goal was to cre­ate the entire web­site using only one image. How is that pos­si­ble? A sprite is a large image that con­tains many smaller images inside it. So, I cre­ated all of the images for the site and placed them all inside one large PNG24 image with a trans­par­ent background.

Sprite from haidabo.com

When call­ing for an image (any image) in the CSS file, spec­ify the sprite as the back­ground image and give it a width and height. Then use unique IDs or classes to shift the back­ground posi­tion specif­i­cally for each image. One prob­lem I ran into dur­ing this process was repeat­ing back­grounds. Sprites don’t work well for repeat­ing images. They do have some lim­ited abil­ity to repeat one-dimensionally, but it’s tricky. To keep it sim­ple, I decided to use sep­a­rate images for my repeat­ing backgrounds.

So, why would any­one want to use this tech­nique? Sure, it’s a bit more work to com­bine all your images and set all those back­ground posi­tions, but in the end it will make your web­site more effi­cient. Each image that is loaded on your site requires a sep­a­rate HTTP-Request (to your server). By com­bin­ing images into a sprite, you reduce the amount of work your server is required to do. This may not make much of a dif­fer­ence for a small site with­out much traf­fic, but as the size of the site and the amount of traf­fic increase, this becomes more of a benefit.

haidabo.com

Tags: , , ,

This entry was posted in the Web Design category.


Leave a Reply


Notify me of follow-up comments via email.