Home arrow Style Sheets arrow Page 3 - Defining a Navigation Bar`s Hover State with CSS Sprites
STYLE SHEETS

Defining a Navigation Bar`s Hover State with CSS Sprites


In this penultimate part of the series, I show how to use the previous CSS sprite background image to define the look of a casual, artistic blog navigation bar in its “hover” state. The simple styling process shouldn't give you any major problems when you use this approach to build a navigation bar for your own websites.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
March 08, 2010
TABLE OF CONTENTS:
  1. · Defining a Navigation Bar`s Hover State with CSS Sprites
  2. · Review: using CSS sprites to define the blog navigation bar's normal state
  3. · Defining the navigation bar's hover state
  4. · Linking the CSS code to the blog's markup

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Defining a Navigation Bar`s Hover State with CSS Sprites - Defining the navigation bar's hover state
(Page 3 of 4 )

As you may have already guessed, decorating the sections of the blog’s links bar in its “hover” mode is only a matter of modifying the X and Y coordinates of the corresponding background image, thus displaying the correct portion (or sprite) of it. This task can be easily accomplished via CSS in the following manner:

/* About Me button */

ul#navbar li:hover#about {

    background: transparent url("bg_blog_buttons.png") -160px 0 no-repeat; 

}

/* Articles button */

ul#navbar li:hover#articles {

    background: transparent url("bg_blog_buttons.png") -161px -314px no-repeat; 

}

/* Blog button */

ul#navbar li:hover#blog {

    background: transparent url("bg_blog_buttons.png") -166px -657px no-repeat; 

}

/* Search button */

ul#navbar li:hover#search {

    background: transparent url("bg_blog_buttons.png") -161px -956px no-repeat; 

}

/* Contact button */

ul#navbar li:hover#contact {

    background: transparent url("bg_blog_buttons.png") -162px -1311px no-repeat; 

}

That’s not rocket science, is it? As I expressed before, defining the visual presentation for the “hover” mode of each section of the navigation bar is a straightforward process reduced to assigning the correct X and Y coordinates to the bar’s background image, and nothing else. For obvious reasons, calculating the values that must be assigned to each of the above coordinates does require doing some math, but nothing that you didn't learn in elementary school!

At this stage, the development of this sample links bar is nearly complete, as its “normal” and “hover” states have been properly defined via the implementation of CSS sprites. Nonetheless, the last step that must be taken is to tie the previous CSS styles to the blog site’s markup, so all of the pieces of this puzzle can fit together as expected.

This assembly process will be done in the last segment of the tutorial, so read the lines to come.


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials