Style Sheets
  Home arrow Style Sheets arrow Creating Rollover Effects with CSS Sprites
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Creating Rollover Effects with CSS Sprites
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2007-02-12

    Table of Contents:
  • Creating Rollover Effects with CSS Sprites
  • Creating rollover buttons with CSS: a traditional approach
  • Improved rollover buttons: using a CSS sprite-based approach
  • Completing the CSS sprite-based rollover example

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating Rollover Effects with CSS Sprites


    (Page 1 of 4 )

    Using CSS sprites can reduce the lag for certain events on web pages, thus making your web site perform more efficiently and improving your visitor's experience. In this first article of a three-part series, you'll learn how to use CSS sprites in the creation of rollover buttons.

    Introduction

    As the experienced web designer that you probably are, I'm sure that you've been using the neat capabilities offered by CSS to create and polish the look and feel of numerous web sites. As you know, armed with a respectable background on the different rules that comprise the CSS specification, it's feasible to do all sorts of clever things, like developing consistent, cross-browser web page layouts, styling several elements of a web document, creating eye-catching navigation bars, etc. And certainly the list goes on and on.

    If all these things that I mentioned above are pretty familiar to you, then creating CSS-based rollover links also has been part of your experience as a web developer. Indeed, the capabilities that come packaged with CSS are truly remarkable either for developing text or image-based rollover buttons, which are commonly included into many modern web sites.

    However, and now speaking more specifically, there's a known issue associated with image-based rollovers, even when they've been created with only a few CSS styles. As you may guess, the different background images that are used for creating the rollover in question are downloaded progressively by the browser, which introduces a small (but noticeable) lag the first time the mouse hovers over the rollover element.

    Logically, this problem isn't present subsequently, since the respective background images has been cached by the browser, which implies that the delay disappears. Nevertheless, at this time maybe you're wondering: can this annoying lag be fixed without using any JavaScript code?

    Fortunately, the answer to this question is yes! The issue in question can be addressed by using a technique popularly known as a "CSS sprite." It consists of creating only one background image, but in this case, this image contains different sections that correspond to each state of the rollover element. Pretty good, right?

    Having created this "special" background image, the rollover effect can be easily created via CSS, by changing its position according to the stages of the link where the rollover will be visible. Besides, this approach has an additional advantage, since it requires working with only one image, something that decreases the number of requests made by the browser.

    Having outlined generally the logic that stands behind the concept of CSS sprites, in this three-part series I'm going to show you how to put this technique to work for you quickly, not only if you want to create rollover buttons, but also in cases where you need to include dynamic banners, and simple gallery images as well.

    Ready to learn how to include your own CSS sprites into your web site? Okay, let's get going!

    More Style Sheets Articles
    More By Alejandro Gervasio


       · In this first tutorial of a three-part series, you'll learn how to use CSS sprites...
       · Great job on this one, much like all of your other tutorials and articles I've read...
       · Thank you for the kind comments on my article. I truly appreciate them, and hope the...
     

    STYLE SHEETS ARTICLES

    - Image Replacement CSS Techniques
    - Using BlueTrip`s Success, Notice and Error C...
    - More Uses for the Thin and Caps CSS Classes ...
    - Styling Definition Lists with the BlueTrip C...
    - Styling Unordered and Ordered HTML Lists wit...
    - Using the BlueTrip CSS Framework`s Thin and ...
    - Adding Borders to Web Page Columns with Blue...
    - Introducing the BlueTrip CSS Framework
    - Using a Background Grid to Assist Web Page L...
    - Extending the Rule Of Thirds for Web Page La...
    - A Two-Column Web Page Layout Based on the Ru...
    - Using the Rule Of Thirds for Web Page Layout
    - Swapping Columns Using the Divine Ratio for ...
    - Using the Golden Ratio in Liquid Web Page De...
    - Fundamental Design Principles for Web Page L...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek