Log in | Jump |

Pinoy Tech

Business, Web Design and Web Development
This thing was constructed on July 5, 2008, and it was categorized as Tutorials and Tips.
You can follow comments through the RSS 2.0 feed. You can leave a comment, or trackback.

Another day, another tip. Not really. I don’t blog everyday (at least not these days…). I am just posting to give a quick tip about CSS sprites. If you don’t know what CSS sprites are? CSS sprites are graphical images compiled in one image. Why do you have to use it? Here are some reasons why.

Benefits

  1. You have a slow website and you have a lot of images being used for your website. Having smaller number of HTTP requests can greatly speed up your website’s loading speed.
  2. Image re-use. Imagine if you have to manage fewer images for your website.

Sprite image:

flower image for css sprite tutorial

CSS code:


div.sprite-sprite-sample {
      width: 144px;
      height: 144px;
      background: url(../images/sprite.gif) 0px -91px no-repeat;
      margin: 0 auto;
}

div.sprite-sprite-sample:hover {
     width: 144px;
     height: 144px;
     background: url(../images/sprite.gif) -144px -91px no-repeat;
}

CSS Sprite Sample:

Using fewer images are definitely the way to go. As promised, the css sprites sample.

In the css sprites example, I used only one image for the colored flower and the grayscale flower. Try hovering your mouse on it.

View working sample here: Creating CSS Sprites

PS. I lied. I used also only used one image for the tabs and the flower backgrounds for the css sprites. Ain’t that cool?

This thing was constructed by .


You can follow comments through the RSS 2.0 feed. You can leave a comment, or trackback.

This thing has 2 Comments

  1. Mark
    Posted July 10, 2008 at 5:02 pm | Permalink

    Fantastic. I learned this while reading an article about lessening HTTP requests to speed up sites.

  2. TEEJAY
    Posted July 10, 2008 at 5:05 pm | Permalink

    Yes Mark, Yahoo has created a wonderful site regarding best practices for speeding up websites.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*