Home arrow Style Sheets arrow Page 3 - Finishing a Casual Navigation Bar with CSS Sprites
STYLE SHEETS

Finishing a Casual Navigation Bar with CSS Sprites


If you’re interested in learning how to use CSS sprites to create engaging, standard-compliant navigational mechanisms that can be used on different web sites with minor modifications, you’ve come to the right place. Welcome to the final installment of a seven-part series that shows you how to build CSS sprite-based navigation bars. This series walks you through the progressive development of a couple of appealing links bars, which use a single background image to define the visual presentation of their sections.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
March 09, 2010
TABLE OF CONTENTS:
  1. · Finishing a Casual Navigation Bar with CSS Sprites
  2. · Review: defining the hover state of the navigation bar
  3. · Creating the active state of the links bar
  4. · Activating different sections of the navigation bar

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Finishing a Casual Navigation Bar with CSS Sprites - Creating the active state of the links bar
(Page 3 of 4 )

As you may have guessed, creating the CSS styles that implement the “active” state of the previous links bar is only a matter of tweaking its background image via the corresponding X and Y coordinates. Since this process should be familiar to you at this point, I suggest you look at the code sample below, which implements this handy feature in a few simple steps. Here it is:

/* About Me button */

ul#navbar li#about a.active {

    display: block;

    width: 162px;

    height: 313px;

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

}

/* Articles button */

ul#navbar li#articles a.active {

    display: block;

    width: 162px;

    height: 343px;

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

}

/* Blog button */

ul#navbar li#blog a.active {

    display: block;

    width: 162px;

    height: 300px;

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

}

/* Search button */

ul#navbar li#search a.active {

    display: block;

    width: 162px;

    height: 355px;

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

}

/* Contact button */

ul#navbar li#contact a.active {

    display: block;

    width: 162px;

    height: 298px;

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

}

Definitely, understanding how the above CSS code works should be a fairly straightforward process to you, since it takes advantage of the functionality of the “background-position” CSS property to implement the aforementioned “active” mode of the links bar.

Also, notice that the sprites displaying the portions of the background image corresponding to this specific mode have been assigned directly to the links of the navigation bar, instead of their item lists. This implies that the implementation of this mode requires altering the markup to some extent as well.

Don't worry if this explanation sounds rather confusing to you, since in the last segment of this tutorial I’ll be coding some examples that will show how to activate different sections of the links bar by using the previous CSS code.

To see how these examples will be created, please click on the link below and read the following lines.


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