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.
Defining the Active State of Menu Sections for a CSS Sprite-Based Navigation Bar - Review: defining the navigation bar's active and hover states (Page 2 of 4 )
As usual, before I start coding the styles required for defining the appearance of the “active” state of the sample navigation bar's sections, I’d like to spend a few moments reintroducing the source code developed so far. It uses the functionality of CSS sprites to create the bar’s “normal” and “hover” states.
With that said, here’s the background image that performs the smooth transition between those states:
And finally, below is the web page that displays the navigational bar by using only a plain HTML unordered list:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div id="footer">
<h2>Footer section</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
</body>
</html>
Definitely, the beauty of this example rests on its capability to create a stylish navigational bar by means of uncluttered, standard markup. The cosmetic part of the whole construction process is achieved simply by altering the X and Y coordinates of the background image that you saw a moment ago. This produces the result visible in the screen shot below:
In this case, the above screen capture shows the look of the fictional “Services” section when a user places the mouse over it, but naturally the same effect will be seen when hovering on the other sections as well.
So far, so good. At this stage, the development of the navigation bar is almost complete. The only thing that remains undone is defining the visual style of its sections in the “active” state. As you might have guessed, accomplishing this only involves playing with the position of the previous background image.
However, the full details of this process will be covered in the following section. Thus, click on the link below and keep reading.