Defining a Navigation Bar`s Hover State with CSS Sprites
In this penultimate part of the series, I show how to use the previous CSS sprite background image to define the look of a casual, artistic blog navigation bar in its “hover” state. The simple styling process shouldn't give you any major problems when you use this approach to build a navigation bar for your own websites.
Defining a Navigation Bar`s Hover State with CSS Sprites - Linking the CSS code to the blog's markup (Page 4 of 4 )
By far, the best way to understand the role that CSS sprites play in the construction of this sample navigation bar is by examining the full source code of the web page that displays its “normal” and “hover” modes. With that premise in mind, below you'll find the XHTML document that renders the bar with the two aforementioned modes up and running. Take a look at it:
<!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 above, the CSS code responsible for visually defining the two main states of the links bar is very easy to follow, so I won’t spend your time (and mine) explaining once again how it works. Instead, I suggest you do something a bit more useful and look at the following image, which depicts the appearance of the bar when the mouse is placed over its “Articles” section:
In this case, the hovered section simply changes the color of its icon, but naturally it’s possible to create a different hovering effect, depending on your particular needs and preferences. The possibilities are endless.
And with this last example, we’ve come to the end of this sixth installment of the series. As usual, feel free to edit all of the code samples shown in this tutorial to give yourself a better understanding of how to work with CSS sprites in all sorts of creative ways.
Final thoughts
In this penultimate chapter of the series, I showed how to employ the previous CSS sprite background image for defining the look of this sketchy navigation bar in its “hover” state. The entire styling process was indeed a no-brainer, so I guess you won't have major problems using this approach when building your own websites.
In the last part of the series, I’ll be discussing how to use the same background graphic that you saw before for creating the “active” mode of the bar’s sections.
Don’t miss the final chapter!
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.