Home arrow Style Sheets arrow Page 3 - Styling the Hover State of a CSS Sprite-Based Navigation Bar
STYLE SHEETS

Styling the Hover State of a CSS Sprite-Based Navigation Bar


In this second part of a series, I show you how to use CSS sprites to create the visual style corresponding to the “hover” state of each section of the sample navigation bar. You will see that this process relies heavily on manipulating the X and Y coordinates of the bar’s background image. This requires doing some math, but nothing especially complicated.

Author Info:
By: Alejandro Gervasio
Rating: 3 stars3 stars3 stars3 stars3 stars / 2
March 02, 2010
TABLE OF CONTENTS:
  1. · Styling the Hover State of a CSS Sprite-Based Navigation Bar
  2. · Review: using CSS sprites to build a stylish navigational bar
  3. · Creating the hover state for each section of the navigation bar
  4. · Binding the CSS code to the structural markup of a web page

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Styling the Hover State of a CSS Sprite-Based Navigation Bar - Creating the hover state for each section of the navigation bar
(Page 3 of 4 )

As I said in the segment that you just read, defining the visual style corresponding to the “hover” state of each section that comprises the navigation bar doesn’t different too much from styling its “normal” versions. Basically, the entire styling process is reduced to assigning to the bar’s background image the appropriate X and Y coordinates, thus displaying its correct portion.

Does this explanation sound a bit confusing to you? Well, fear not and pay attention to the following CSS fragment, which should quickly dissipate your confusion:

/* About section */

ul#navbar li:hover#about {

background: #800040 url("bg_navbar.png") -130px 0 no-repeat;

}

/* Services section */

ul#navbar li:hover#services {

background: #800040 url("bg_navbar.png") -130px -100px no-repeat;

}

/* Products section */

ul#navbar li:hover#products {

background: #800040 url("bg_navbar.png") -130px -200px no-repeat;

}

/* Articles section */

ul#navbar li:hover#articles {

background: #800040 url("bg_navbar.png") -130px -300px no-repeat;

}

/* Blog section */

ul#navbar li:hover#blog {

background: #800040 url("bg_navbar.png") -130px -400px no-repeat;

}

/* Contact section */

ul#navbar li:hover#contact {

background: #800040 url("bg_navbar.png") -130px -500px no-repeat;

}

There you have it. As you can see above, creating the “hover” state of each section of the sample links bar requires only moving the pertinent background image to the proper position on screen, thanks to the manipulation of its X and Y coordinates. In this particular case, the CSS code that performs this process seems to be somewhat complex, but that’s simply a misleading impression caused by the number of sections that need to be styled.

Now that you've grasped the logic that drives the previous styling procedure, it’s time to how this set of CSS styles can be tied to the structure of the web page shown in the preceding segment.

This will be done in the last section of this tutorial. So click on the link below and 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 7 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials