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 - Review: using CSS sprites to define the blog navigation bar's normal state (Page 2 of 4 )
As usual, before I start coding the CSS styles required to define the look of the blog’s navigational bar when users hover on it, I"m going to reintroduce the source code developed so far. The code shows how to take advantage of the functionality offered by CSS sprites to style the bar in its normal state.
Having said that, here’s the background image used to create the CSS sprites that give the bar its sketchy look:
Unquestionably, the above picture demonstrates in a nutshell the driving logic of CSS sprites, since it behaves as a container for all the states of this sample links bar. Do you see the point to using this approach? Great! Now look at the following code fragment, which renders the bar in its normal mode:
<!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>
Here, it’s clear to see how the simple manipulation of the X and Y coordinates corresponding to the previous background image permits you to define the initial appearance of the blog’s navigation bar. Of course, the beauty of using this approach is that the entire styling process demands only a single HTTP request to the web server. That’s faster and better, right?
In addition, the following screen capture shows how this sample links bar is displayed on screen when the earlier web page is rendered by the browser:
Well, having created the CSS code responsible for defining the “normal” state of the bar, the next thing that we must do is add the styles that will define the “hover” mode of its sections.
This topic will be discussed in depth in the segment to come. So please click on the link below and keep reading.