Advanced CSS Menu Trick
CSS really opens the doors to a lot of powerful and rich opportunities. It is funny how such minor things can create a whole new look, feel, and effect of a site. The beauty of CSS really is that it gives you power, but not too much power. It is not a tool like flash that really invites you to run away and take things too far.
We are now coming to a point where the browsers are supporting a lot of new features, giving us more opportunities to take advantage of previously unused pseudo elements. This example, “advanced css menu tricks” will work perfectly in any modern browser, yet still be fully functional in your older version of IE as well.
The goal of the demo – example
What we want to do here, is instead of simply altering the state of the navigation item the user is currently rolling over, we want to alter the non navigation items as well. This will help focus the users attention on the item they have selected on, and create a new look and feel for the site overall. Want to see it in action? Look at my demo page before we start.
The first step – CSS roll overs
The first step of the game is building some CSS roll overs. We want to keep things accessible so I have opted to use an IR technique. Essentially we create an image that has both the static, active and rolled over state all lined up next to each other. We then set the image as the background of th element, but the width is only wide enough for one state of the image (so if the button image is 600px wide with all three states, we make the navigation element as a 200px wide button). We then set the text indent really high and overflow to hidden so that it pushes the text out of the box. Then we only see the image even though there is still HTML text on the page for search engines and accessibility.
Image Examples
Menu Before
Button Sliced, fixed and hover states

The CSS
#main_nav { list-style: none; margin: 0; padding: 0; }
#main_nav li { float: left; }
#main_nav li a { text-indent: -999999px; overflow: hidden; display: block; height: 72px; }
#home { background: url(../images/navigation/home.gif); width: 103px; }
#home.active { background: url../images/navigation/home.gif) -103px 0; }
The HTML
<ul id="main_nav">
<li><a href="index.html" accesskey="3" id="home" title="Home Page">Home Page</a></li>
<li><a href="about-us.html" accesskey="4" id="about" title="About 3.7 Designs">About Us</a></li>
<li><a href="web-design.html" accesskey="5" id="webdesign" class="active" title="Web Design and Development">Web Design</a></li>
<li><a href="graphic-design.html" accesskey="6" title="Graphic Design and Marketing" id="graphicdesign">Graphic Designs</a></li>
<li><a href="keyword-optimization/michigan-seo.html" accesskey="7" title="Search Engine Optimization and Marketing" id="seo">Search Engine Optimization SEO</a></li>
<li><a href="ann-arbor-marketing.html" accesskey="8" id="contact" title="Contact Us">Contact Us</a></li>
</ul>
Then when we want to change the state of the button we simply adjust the background position to be -200px (or the size of the button itself) pulling the different state of the button into view. The reason for doing it this way then simply swapping images, is the latter method tends to create flickering in some browsers.
At this point most people have it set so that if an item is hovered on (#home for example) it switches the background-image position. This creates the standard run of the mill css roll over. However we want to do something else, something more unique. We want to have every roll over item on the menu change except the one you are hovering on. This requires a little css trickery!
IE7, Safari, Firefox, all support the :hover pseudo selectors so let’s take advantage of that. What we need to do is have all the menu items change the background-image position when the menu item itself has been rolled over. Then the item that is hovered on is set to have the background-position: 0px to keep it from moving when the rest do.
The CSS
#main_nav:hover li a#webdesign { background-position: -280px; }
#main_nav:hover li a#home { background-position: -206px; }
#main_nav:hover li a#graphicdesign { background-position: -340px; }
#main_nav:hover li a#contact { background-position: -232px; }
#main_nav:hover li a#about { background-position: -242px; }
#main_nav:hover li a#seo { background-position: -540px;
This pulls each menu item’s background position back when any of #main_nav has been hovered on. Now all we have to do is set the hovered items to have a background-position of 0
#home { background: url(../images/navigation/home.gif); width: 103px; }
#home:hover { background: url(../images/navigation/home.gif) 0 0 !important; }
The HTML is all set, already coded! Now you are ready to rock and roll except for that pesky IE5.5+. Luckily there has been a behavior file developed called cssHover.htc that will fix this issue. Simply download it, and copy and paste the following code into an IE5+ specific style sheet.
body {
behavior: url("/css/csshover.htc");
}
The Whole Shabang
CSS
#main_nav { list-style: none; margin: 0; padding: 0; }
#main_nav li { float: left; }
#main_nav li a { text-indent: -999999px; overflow: hidden; display: block; height: 72px; }
#home { background: url(../images/navigation/home.gif); width: 103px; }
#home:hover { background: url(../images/navigation/home.gif) 0 0 !important; }
#home.active { background: url../images/navigation/home.gif) -103px 0; }
#main_nav:hover li a#home { background-position: -206px; }
HTML
<ul id="main_nav">
<li><a href="index.html" accesskey="3" id="home" title="Home Page">Home Page</a></li>
<li><a href="about-us.html" accesskey="4" id="about" title="About 3.7 Designs">About Us</a></li>
<li><a href="web-design.html" accesskey="5" id="webdesign" class="active" title="Web Design and Development">Web Design</a></li>
<li><a href="graphic-design.html" accesskey="6" title="Graphic Design and Marketing" id="graphicdesign">Graphic Designs</a></li>
<li><a href="keyword-optimization/michigan-seo.html" accesskey="7" title="Search Engine Optimization and Marketing" id="seo">Search Engine Optimization SEO</a></li>
<li><a href="ann-arbor-marketing.html" accesskey="8" id="contact" title="Contact Us">Contact Us</a></li>
</ul>
- Author: Ross Johnson
- Date: Saturday, December 22, 2007
- Comments: 170 Comments
- Categories:
About This BLOG
Since inception, this blog has covered a plethora of topics. Excited by all things design, I spent six years with out a focus. A year ago I discovered my true passion... designing with psychology (primarily as it related to the web). Many thanks to my Web Design Agency, 3.7 DESIGNS that gifts me time to publish my findings.
The Latest Buzz
You should follow us on twitter here.





比较牛
thanks you bro.
[...] start things off with a technique that isn’t too advanced, to get us limbered up. The focusing and blurring of navigation menu items is a powerful way to add attention to the selected item. This technique is different than [...]
like it
[...] Crear un menu con efecto Blur [...]
Thx u bro.
thx you very much.
[...] Advanced CSS Menu Trick [...]
[...] start things off with a technique that isn’t too advanced, to get us limbered up. The focusing and blurring of navigation menu items is a powerful way to add attention to the selected item. This technique is different than [...]
Thanks
Thanks………
[...] came across this website the other day using some really ingenious css that would change the state of a menu item as you [...]
[...] 13. Advanced CSS Menu Trick [...]
awesome tricks boy. Really great.
[...] Otro menú avanzado hecho con CSS Lo que queremos hacer aquí, es, en vez de alterar simplemente el estado del objeto de [...]
It does work in IE6 with the behavior file mentioned at the end of the article.
awesome tricks boy. Really great.
How do you get the whole thing from breaking apart when you play around with stretching out the browser?
My links just float down when you resize.
Vadim.
Thank you.
[...] Advanced CSS Menu Trick [...]
[...] 2) Advanced CSS Menu Trick(一个新的菜单设计理念即:当鼠标悬浮在一个导航项目上时,它通过改变非导航项目的状态来集中用户对当前鼠标悬停项目的注意力,并为整个站点创建了一个新的面貌和感觉。适用于市面上任一流行的浏览器同时也适合旧版的IE) [...]
[...] Advanced CSS Menu Trick [...]
[...] Advanced CSS Menu Trick [...]
Hi,
Amazing activities
Great !!!!!!!
I have read this Blog and you have shared good information about Advanced CSS Menu Trick……….
Nice Post!!!!!!!
Thanks.
[...] Advanced CSS Menu Trick [...]
Here at BMSB.com the theological holding that Han shot first in the first episode of the Holy Trilogy is considered blasphemy. That’s why I’m awfully confused to come across the following picture thank you.
thank you.
Wow, I had no idea it was that easy!
[...] Advanced CSS Menu Trick We are now coming to a point where the browsers are supporting a lot of new features, giving us more opportunities to take advantage of previously unused pseudo elements. This example, advanced css menu trickswill work perfectly in any modern browser, yet still be fully functional in your older version of IE as well. [...]
Wow, I had no idea it was
thank youu.
web site::)
Couldn’t you get the same effect if you set up the image with the 3 states lined up vertically? That way the CSS would have all the same values for the state change position. Yes, no? Thanks for a great tutorial.
seslichat http://www.bizimsokak.biz and sesli sohbet http://www.seslichatbiziz.com
[...] Advanced CSS Menu Trick [...]
Wow, I had no idea it was that easy!
[...] design / development / UX related classes at a local college. I have pioneered various different CSS techniques and tricks, which I write about on my 3.7CREAT.TV blog. I am co-host of the WebAxe podcast, and [...]
möcten sie chat?kommen sie bitte unsere web seite http://www.bizimsokak.biz http://www.seslichatbiziz.com
möcten sie chat?kommen sie bitte unsere web seite http://www.bizimsokak.biz http://www.seslichatbiziz.com ….
The sample site is a fantastic example of the CSS trick. Just loved it!!!
sesli chat te tek adres…
Do as my client is doing on the Internet and as mhy client has done
in the past with self-publishing which has led to his books being
published in 20 languages and 27 different countries. Jump into it
full force and correct course when necessary. You will have to because
Google keeps changing the rules of the game.
Google Page rank counts but not near as much as content. As the Internet
experts all say, “Content is King.”
Unfortunately, when most people see successful individuals make a
system like the Internet work, but they themselves don’t understand,
they make up stories. Stories abound about how successful individuals
are lucky, how they have gotten all the breaks in life, and how they
have to be dishonest to make it in this world. Most of these stories
are either untrue or out-and-out lies.
It turns out that becoming an Internet success is a lot simpler than
that. Success, after all, is based on commitment, perseverance, and
common sense. Above all, this is the most important secret to getting
started on an Internet business: Do it badly — but at least do it!!
That is exactly what I am doing this week with the launch of three
new websites for a client:
I personally think PR is not as important as it was. Google seems to be steering down a lexical keywords / page keyword density route (back to the old days of excite! in 96). Link text is still as important as ever, both internal and external. Whatever, Google is doing these days they seem to be purposefully leaving themselves open to increased manipulation by SEO professionals and weakening the index as a whole. I mean bulk cross-linking and lexical keywords stuffing in titles, they should have an algorithm to kick that stuff out, shouldn’t they? but I plead guilty on all counts;)
[...] Advanced CSS Menu Trick [...]
[...] design / development / UX related classes at a local college. I have pioneered various different CSS techniques and tricks, which I write about on my 3.7CREAT.TV blog. I am co-host of the WebAxe podcast, and [...]
[...] Advanced CSS Menu Trick What we want to do here, is instead of simply altering the state of the navigation item the user is [...]
merci
cok mersi thank you
It can also get kind of hairy when trying to get it to understand what a conversion is. Instead of just any click, it needs to be one specific click
Thanks you very much. It is wonderful..