Home arrow Style Sheets arrow Page 3 - Defining the Active State of Menu Sections for a CSS Sprite-Based Navigation Bar
STYLE SHEETS

Defining the Active State of Menu Sections for a CSS Sprite-Based Navigation Bar


In this third part of a series, I put the final touches on our sample navigation bar, which uses the functionality of CSS sprites to define the visual presentation of the “normal,” “hover” and “active” states of its sections. Constructing a graphic user interface like this is a two-step process. First, one creates a good-looking background image, and then tweaks its X and Y coordinates via CSS.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
March 03, 2010
TABLE OF CONTENTS:
  1. · Defining the Active State of Menu Sections for a CSS Sprite-Based Navigation Bar
  2. · Review: defining the navigation bar's active and hover states
  3. · Defining the visual styles for the navigation bar's active state
  4. · Finish building the navigation bar

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Defining the Active State of Menu Sections for a CSS Sprite-Based Navigation Bar - Defining the visual styles for the navigation bar's active state
(Page 3 of 4 )

In reality, creating the visual presentation for the “active” state of each section of this example navigation bar is a two-step process that must be performed in the following order: first, it’s necessary to code the CSS styles that will give the sections their correct appearance, and then modify the bar’s structural markup to indicate which of these sections is currently viewed by the user.

In a real-world environment, this last step should be accomplished dynamically via a server-side language such as PHP or Ruby; however, for demonstrative purposes in this tutorial, I’ll be showing how to do this statically.

Having explained that, here’s the new set of CSS styles that uses the earlier CSS sprites to define the “active” state of the aforementioned sections:

/* About section */

ul#navbar li#about a.active {

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

}

/* Services section */

ul#navbar li#services a.active {

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

}

/* Products section */

ul#navbar li#products a.active {

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

}

/* Articles section */

ul#navbar li#articles a.active {

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

}

/* Blog section */

ul#navbar li#blog a.active {

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

}

/* Contact section */

ul#navbar li#contact a.active {

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

}

As seen in the previous code sample, creating the “active” state of every bar section is done simply by assigning a class called “active” to its building links, which also requires modifying the X and Y coordinates of the corresponding background image to display the correct portion of it. Of course, at this point the inner working of this process should be pretty familiar to you, as it’s very similar to other examples shown in this and previous tutorials of the series.

Well, having created the CSS styles that define the “active” state of the sections of the navigational bar, we need to modify its markup, so this state can be properly reflected visually.

This process will be discussed in the following segment. Therefore, to learn more, click on the link below and keep reading.


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 3 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials