Sean
October 27 2007 @ 10:51PM #
Thanks Elliot!
Thats just what I needed.
Wow..that’s pretty slick. That is WAY better than using a ton of javascript rollover code.
Thanks
Hey guys – I’m glad you’re finding it useful! Coincidentally, Nick La just posted a very similar tutorial over on Web Designer Wall. It’s worth checking out to hear it being explained in a slightly different way to mine, and it might help solidify any issues you’re unsure of. It’s a beautiful site, too.
I’m seeing this solution more and more, and under certain conditions it seems to have as many drawbacks as advantages.
If you’re building a totally static site that will never grow or change, putting all your nav in one image would work. But sites will inevitably change, and increasingly clients want more control over their pages (via CMS), including the navigation.
What happens when an extra layout column is needed and the margins between each button need editing – or when new buttons are added. The designer has to redesign and re-export everything with Photoshop until the next time.
Nick’s example seems somewhat more practical in that the buttons are sliced individually. Adjusting margins with CSS or adding more list-items in HTML is simple, with or without a CMS.
But with increasing numbers of CMS-driven sites, wouldn’t a more flexible/scalable solution like this one (Sliding Doors/Sprites hybrid) make updates easier in the future?
I dunno, just another way of looking at it. (And regardless, the Trojan site is fantastic!)
@ Darren: You’re not wrong. As with any web design / development technique, this is but one method, and it has both pros and cons. I certainly wouldn’t say this is the be-all-and-end-all of image-based navigation; just one way of getting things done. The example you gave is a great alternative and certainly more scalable, but you pay the price of having browser-rendered text.
Personally I’ve run into very few problems with the technique above; I would argue that the main navigation of a site should change very little if a site’s structure has been well planned. You could then use less image-dependent methods for more changeable sub-navs.
But obviously this is in an ideal world! :) Thanks for the kind words, man.
[…] looking back in a magazine today (I wanted to look at the CSS navigation tutorial featured on this site) I found an Illustrator tutorial I could look at, concerning masking. I wouldn’t have […]
A very good and thorough overview.
It’s a quite long and tedious process but it yields very good results. It’s kind of why I wrote a plugin for Adobe Fireworks that does most of the work for you. I would have made it for Photoshop except that I don’t know of any way to get the guide or slice data from a Photoshop document using the scripting API.
[…] Tutoral CSS better nav image replacement | Descargar archivos […]
[…] Most importantly, it only used one image file; a technique often referred to as ‘CSS sprites’. Read full article. (0 hits) Posted by Dmitry | November 7, […]
I love these css sprites even more than I love the tasty soft drink!
Elliot you are awesome. Works like a charm!
Check it out: michaelrossback.com
Paul, using a single image is actually better for two reasons. Firstly, a single image tends to have a smaller filesize than the total filesize of several images. Secondly, having less files means less server requests (a single image is only requested once, regardless of how many times it is used on a page because browsers cache the image after the first download) which is also faster.
The downside is that having a single image tends to make the css for choosing the right part of the image more complicated.
I’m glad you guys have been finding this useful and thanks for the supportive words. I hope to reprint more of my other magazine tutorials here soon.
@ Steve: To get it working for a vertical navigation, just do the opposite: make the ‘top’ values change instead of the ‘left’ ones.
@ Rude: Yeah, you’re right, actually. Well spotted. I’m pretty sure there’s a more accessible technique you can use instead of outline:none, although I can’t remember it right now. Any ideas?
@ Andrew: Thanks for answering Paul’s question!
[…] CSS Tutorial: better nav image replacement […]
Another problem with the image replacement method you’ve used (aside from the outline stretching out towards the left when clicked on in Firefox) is that none of the text is viewable with images off because of the negative text-indent.
I actually wrote something very similar to this last year but used a different IR technique which leaves the text on screen if images are off (the article also covers how to pair the technique with a Suckerfish dropdown so you can ignore the last half if you’re only interested in the single image/nav part).
Just wanted to say a wow for nice grided transparent design.
And mention this old article, as a related one in Persian(farsi) language: http://weblog.corelist.net/archives/1384/05/08/css-rollover/
;)
Isn’t exactley what i killed my brains with but it does the trick. Elliot, when i made my css menu i never used text between a tags. Regardin the email i’ve sent you.
All the best man. Take care.
[…] Güzel bir CSS ile yapılmış resimli menü örneği. Bağlantı […]
[…] came across an excellent tutorial for easy image swapping using CSS. I ended up using this technique to do the main nav links for the […]
Great article!
I’ve used css sprites on a couple projects but with a single image for each link’s state (off, hover, focus). The benefits of using a single image for the entire nav makes sense to me and I’ll use that technique from here on out.
As for hiding the HTML link text, I recently started placing a span around the actual text (inside the a tag) that simply hides the text. For example:
span.linktext {
visibility:hidden;
}
It works fine in all major browsers.
Thanks again!
The problem (forgive me Elliot) is that large sprites take too long to download. I can see your point if the background is complex or if each button is distinct in design (as per your example) but if the nav items all use a similar background then straight up :link and :hover selectors with independent graphics will do just as nicely.
And I don’t think it would work so well if your Nav is generated dynamically. Forgive the shameless plug but my 10-yr old son’s site is an example (www.car-mad.com). The CSS would need an infinite collection of distinct classes to deal with an ever-changing navigation – hence the decision to KISS.
The sprite concept is sound, but I would urge anyone out there to weight up the pros and cons first.
[…] Elliot Jay Stocks » CSS Tutorial: better nav image replacement Uses css sprites (tags: css sprites design navigation image replacement) […]
I enjoyed reading your tutorial and it helped me practice what I read in the book: “The Art & Science of CSS” put out by Sitepoint. The problem I have with the whole method is that it’s not accessible in terms of being able to enlarge the font-size and for the club site I’m trying to redo, there are older folks and some with sight or reading problems who really need to have large fonts. I thought of just making the tabs large, but thought they’d probably look strange if too large and for my “legally” blind friends, I don’t know how big is big enough. I can have him or anyone click a link to increase or decrease all font sizes – when using ems or %. I’m too embarrassed to give the club URI out at the moment. When I update, then I’ll give it out. ; ~)
Other than that problem, it was a great read and I enjoyed playing with it and then learning my problem before I went too far with it. In the book I mentioned, it told of a whitespace problem in IE6 (of course) and at the bottom IE6 shows a line and then an extra space. To cure it, their remedy to trick it into not putting whitespace around, was on the tag #nav (0r #menu) to add float: left; and then style the tag #nav li {
margin: 0; padding: 0; float: left; width: 100%; } The float and width removes the whitespace on vertical navigation lists. If anyone was having that problem, hope their solution helps you. It’s a great book!
Thanks for the terrific read and I’ll be back reading more!
Just one question….
What happens if you enlarge the text, does it get effected??
Hi Elliot,
Just want to say big thanks for the tutorial! the navigation works on firefox but not on the latest version of IE/safari. Is there a method to solve this problem?
thanks a bunch
@ Missy: Actually, one large sprite image is smaller in filesize than several individual images combined, which is one of the benefits of this technique. Please see Andrew Ingram’s comment above. However, you’re right about how people should weigh up the pros and cons before deciding on this approach. It goes without saying that this method is unsuitable for dynamically-generated menus.
@ Jermayn: No, it won’t get effected if you enlarge the text, as specific, pixel-based heights have been declared. This has a downside in that you might want the text size to increase, but if that’s the case, I would advise against using image replacement.
@ Paula: I’ve just tested it on Safari 3 and IE7, and it appears to be working fine.
Hi Elliot,
Great Tutorial, got it working well, however, I was wondering how this could be developed to work on a fixed width, centred design?
Any tips greatfully received!
[…] Uma informção é necessária saber: neste tutorial é usado o fast CSS rollover para chamadas simples, claro que também é possível otimizar as imagens posteriormente para alcançar pesos condizentes com uma facilidade de transferência e rápida carga da página, combinando imagens para um resultado final. Neste ponto recomento a leitura de Better Nav Image Replacement. […]
Does anybody have any examples of vertical nav? im trying to get one working but have got a bit lost! Numbers aren’t my strong point. iv changed my ‘distance from left’ to distance from top’ and visa versa and iv also changed the width css elements to height and also ‘left’ to ‘top’
am i missing something else?
I’m new to CSS Sprites. It took me a long time to code this out, although the measurements were made easier with Andrew’s Sprite Menu plug-in for Fireworks.
Very cool, Elliot!! Thanks!!
I just can’t seem to get the “selected” state to work on any page though. I also tried Andrew’s Sprite Generator…same deal with his version…no “selected” state on any of the pages…either in Firefox or IE7.
Any ideas?
Hi – Great menu! I am a bit new to CSS and I have having trouble with positioning… In your demo download, the menu will slide with a broswer window resize. (So if I resize my browser from right to left, the menu will slide along with it). How can I make it so the menu sticks in one spot and doesn’t move when I resize the browser window.
I know it has to do with relative vs. absolute positioning but I can’t figure out where in CSS to edit it. Thx.
css layer examples / properties and layer attributes
http://css-lessons.ucoz.com/css-layer-properties.htm
I thought I was doing the tutorial wrong because I was getting the flicker effect in IE, but I uploaded the exact files and it was still flickering. Anyone has any suggestions?
[…] Better Nav Image Replacement – by Elliot Jay Stocks […]
Recent Comments: