Code: spriteNav
Here’s a really simple way to make mouseover effects for your navigation without the need for any JavaScript or image preloading. It’s called spriteNav because it involves a technique very similar to the way that 2D sprite animation was created for old video game consoles.
1
To start out we need to create a graphical “sprite sheet” that contains our “on” and “off” button states. I created an example image in GIF and PNG format. The PNG format can be opened in Fireworks MX+ and modified to suite your needs. Anyway, here’s the example images:
![]()
nav.png
The file has both “on” and “off” button states. We will use CSS to display the appropriate state on :hover and non :hover events.
2
Now let’s build the html for our navigation. I’m building the nav as an unordered list because it is easy to maintain and follows semantics. Since navigation is a list of areas within the site, it makes sense to make the navigation an html list… right? Here’s our HTML code:
<ul id="nav"><li><a href="#">Nav Point</a></li><li><a href="#">Nav Point</a></li><li><a href="#">Nav Point</a></li><li><a href="#">Nav Point</a></li><li><a href="#">Nav Point</a></li></ul>
Notice that we gave the < ul > tag an id of “nav”, this is important for the next step.
3
It’s time to create our CSS that will format this simple unordered list into a pretty navigation block. Here we go:
#nav,#nav li {margin: 0;padding: 0;list-style: none;}
This tells the browser not to indent or display the little bullets that are normally associated with unordered lists.
#nav a {width: 94px;height: 26px;background: url(nav.png) no-repeat;color: #666;display: block;font: bold 12px/26px Arial, sans-serif;text-decoration: none;text-indent: 14px;}
This bit of code forces all links within the navigation list to use our nav.png image as its background (make sure you reference the image correctly). The “display:block” part allows the link to receive a click or :hover anywhere within the specified width and height attributes. The “/26px” part make the text vertically centered within each button.
#nav a:hover {background-position: 0 -26px;color: #900;text-decoration: none;}
This part tells the browser to move the background image up 26 pixels when a link is moused over.
Example
Believe it or not, that’s it. All you have to do is put the above three steps together and you have yourself a very simple graphical navigation. I built an example page so that you can see what the navigation looks like when it’s all incorporated into one page. Have fun!







