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.
Finishing a Casual Navigation Bar with CSS Sprites - Review: defining the hover state of the navigation bar (Page 2 of 4 )
Right at the beginning, I mentioned that defining the “normal” and “hover” states of this sample navigation bar was easy to grasp. However, just in case you don't recall the details, below I included the full source code corresponding to this example, complemented with the background image that gives the bar its final appearance.
Take a look at the following code fragment, please:
<!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>
As you can see, creating the “normal” and “hover” modes of the above links bar has more to do with correctly positioning its background image than with anything else. For this particular example, the image responsible for defining the sprites corresponding to each section of the bar is the following:
And finally, here’s an additional screen shot that shows the output generated by the earlier code sample. Check it out:
Not too bad, eh? At this point, the navigation bar not only looks pretty attractive, but displays an appealing hovering effect on its sections without a single noticeable delay, thanks to the use of the previous CSS sprite graphic. However, as I said in the introduction, its behavior can be enhanced even further with the implementation of an “active” mode, which permits users to know what section is currently being visualized.
In reality, this feature has been partially implemented within the “About Me” tab, but only at the markup level. Therefore, in the next segment I’ll be defining the CSS styles that will make the “active” mode work for all of the bar’s sections.
Want to learn how this will be done? Then click on the link below and read the lines to come.