Noupe
Jun 02 2009Sexy Drop Down Menu w/ jQuery & CSS
- By Editorial
- Posted in TUTORIAL
- 700 comments
Advertisment
Studies show that top navigations tend to get the most visual attention when a user first visits a site. Having organized and intuitive navigation is key — and while most drop down menus may look aesthetically pleasing, developing them to degrade gracefully is also essential. In this tutorial I would like to go over how to create a sexy drop down menu that can also degrade gracefully.
border:1px solid #E7E5DD; padding:20px" class="img">View Demo of Sexy Drop Down Menu
Step1. HTML
First create an unordered list for your base top navigation. Then simply nest another unordered list for your sub navigation.
<ul class="topnav"> <li><a href="#">Home</a></li> <li> <a href="#">Tutorials</a> <ul class="subnav"> <li><a href=index.php?i=1&m=1&u=http%3A%2F%2Fwww.noupe.com%2Ftutorial%2F%22%23%22%3ESub Nav Link</a></li> <li><a href=index.php?i=1&m=1&u=http%3A%2F%2Fwww.noupe.com%2Ftutorial%2F%22%23%22%3ESub Nav Link</a></li> </ul> </li> <li> <a href="#">Resources</a> <ul class="subnav"> <li><a href=index.php?i=1&m=1&u=http%3A%2F%2Fwww.noupe.com%2Ftutorial%2F%22%23%22%3ESub Nav Link</a></li> <li><a href=index.php?i=1&m=1&u=http%3A%2F%2Fwww.noupe.com%2Ftutorial%2F%22%23%22%3ESub Nav Link</a></li> </ul> </li> <li><a href=index.php?i=1&m=1&u=http%3A%2F%2Fwww.noupe.com%2Ftutorial%2F%22%23%22%3EAbout Us</a></li> <li><a href="#">Advertise</a></li> <li><a href="#">Submit</a></li> <li><a href=index.php?i=1&m=1&u=http%3A%2F%2Fwww.noupe.com%2Ftutorial%2F%22%23%22%3EContact Us</a></li> </ul>
Step2. CSS
Next, it’s time to style the navigation wireframe with CSS.
ul.topnav { list-style: none; padding: 0 20px; margin: 0; float: left; width: 920px; background: #222; font-size: 1.2em; background: url(topnav_bg.gif) repeat-x; } ul.topnav li { float: left; margin: 0; padding: 0 15px 0 0; position: relative; /*--Declare X and Y axis base for sub navigation--*/ } ul.topnav li a{ padding: 10px 5px; color: #fff; display: block; text-decoration: none; float: left; } ul.topnav li a:hover{ background: url(topnav_hover.gif) no-repeat center top; } ul.topnav li span { /*--Drop down trigger styles--*/ width: 17px; height: 35px; float: left; background: url(subnav_btn.gif) no-repeat center top; } ul.topnav li span.subhover {background-position: center bottom; cursor: pointer;} /*--Hover effect for trigger--*/ ul.topnav li ul.subnav { list-style: none; position: absolute; /*--Important - Keeps subnav from affecting main navigation flow--*/ left: 0; top: 35px; background: #333; margin: 0; padding: 0; display: none; float: left; width: 170px; border: 1px solid #111; } ul.topnav li ul.subnav li{ margin: 0; padding: 0; border-top: 1px solid #252525; /*--Create bevel effect--*/ border-bottom: 1px solid #444; /*--Create bevel effect--*/ clear: both; width: 170px; } html ul.topnav li ul.subnav li a { float: left; width: 145px; background: #333 url(dropdown_linkbg.gif) no-repeat 10px center; padding-left: 20px; } html ul.topnav li ul.subnav li a:hover { /*--Hover effect for subnav links--*/ background: #222 url(dropdown_linkbg.gif) no-repeat 10px center; }
Step3. jQuery
For those who are new to jQuery, you can learn about it here.
The following script contains comments explaining which jQuery actions are being performed.
$(document).ready(function(){ $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*) $("ul.topnav li span").click(function() { //When trigger is clicked... //Following events are applied to the subnav itself (moving subnav up and down) $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click $(this).parent().hover(function() { }, function(){ $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up }); //Following events are applied to the trigger (Hover events for the trigger) }).hover(function() { $(this).addClass("subhover"); //On hover over, add class "subhover" }, function(){ //On Hover Out $(this).removeClass("subhover"); //On hover out, remove class "subhover" }); });
*To degrade gracefully, we only show the drop down menu trigger to those who have javascript enabled.

This is what it looks like when javascript is disabled:

border:1px solid #E7E5DD; padding:20px" class="img">View Demo of Sexy Drop Down Menu
Conclusion
Note: I went ahead and added the rounded corners to the demo (CSS3 – Only supported in Firefox, Safar, & Chrome). If you would like to give it a try, check out this tutorial.
Experiment and customize this to fit your needs! If you have any questions, concerns, suggestions, or comments, please do not hesitate to let me know.
Author: Soh Tanaka
Soh Tanaka is a Los Angeles based Web Designer and blogger, who recently launched a CSS Web Gallery called Design Bombs. For more front-end web development tutorials, check out his web design blog or you can follow him on twitter @SohTanaka
Write for Us! We are looking for exciting and creative articles, if you want to contribute, just send us an email.
About the Author
Comments and Discussions
categories
Advertisment
Advertise with us!Popular Articles
- Educational Resources for Studying Graphic Design
- 50+ Useful CSS Tools And Generators for Developers
- Best Illustrator Tutorials from 2010
- 30 Fresh AJAX Tutorials And Techniques
- A Showcase of Beautifully Designed Infographics
- CSS3 Tutorials to Brighten Up Your Day
- Excellent jQuery Navigation Menu Tutorials
- An Explosion of Adobe Fireworks Resources
- Cool and Useful jQuery Image and Content Sliders ..
- Photoshop Tutorials To Suit Your Taste
Smashing Magazine
- Smashing Daily #7: Wheels, Print And Bingo
- Replicating MySQL AES Encryption Methods With PHP
- How To Choose The Right Face For A Beautiful Body
- Quick Course On Effective Website Copywriting
- A Foot On The Bottom Rung: First Forays Into Responsive Web Development
Fleaty Is Back!
After months of silence, our comic strip on Web design is now back. Illustrated by Ricardo Gimenes, we'll be publishing a new cartoon every Friday. Check out the new cartoon.
Smashing Job Board
- Mobile UX/Visual Designer - Gravity Mobile - (San Francisco, CA) - FullTime
Gravity Mobile is a pioneering mobile development shop, located in the SOMA district of San Francisco. We design and build innovative mobile applications with beautiful…
- Mid/Senior Front-End Web Developer - Motricity - (Mesa, AZ) - Freelance
Motricity is a leading provider of relevance-driven mobile merchandising, marketing, and advertising solutions, enabling advertising agencies, consumer brands and…
Smashing Directory
- Clikzy Creative
Located in Alexandria, UNITED STATESClikzy Creative is a Washington, DC based web design and marketing firm. We focus on custom interactive website design, and…
- Infragistics
Located in cranbury, UNITED STATES
- Jobtimiser - oben stehen!
Located in Freiburg, GERMANYJobtimiser develops holistic and sustainable Marketing Strategies. With Experts from several Online Marketing Areas we believe, along…
Noupe Links
The Smashing Family

Lucas, 07 January 2012
where i can get the images ? demo not working
amir, 10 January 2012
how can i make the sub menu horizontal?
Jornes, 11 January 2012
This menu is really nice. Love it very much! =)
Nick, 11 January 2012
Seems like a very nice drop down menu, but…
Your demo page link STILL doesn’t work !
adgfx, 12 January 2012
Demo is not there, i tried the code.. css is rendering but the sub_menu is not active. does it have to do with the image files in the css?? what size r those images.. width & height?
Nick, 12 January 2012
You got it, the submenu is dependant on an image… no image, no dropdown menu :) just use a background: url of an arrow image for ul.topnav li span … i tried it with a width: 15px;height: 10px; one and it does fine for demo purposes
Jonny, 27 January 2012
I had the same issue as adfgx, but when I tried your solution, it didn’t work. Still no dropdowns. I have a GIF, with the correct file name, and correctly sourced. And tips?
Ryan, 18 February 2012
@ Johnny: I had the same problem you did, and after spending a couple of hours trying different fixes, I realized I did not fully copy the jquery code, and some of it was missing. I re-copy and pasted it and it worked fine. Try looking over your code again and make sure everything is there.
Marc, 13 January 2012
Hi guys,
I couldnt find the images here too, but I used google to find them for me.
I found an spanish version of this tutorial which presented the images for us
go here : http://micodigobeta.com.ar/?p=517 let google translate the page for you and at the bottom you will find a link with the download.
if that doesnt work, use this link : http://www.google.nl/search?sourceid=chrome&ie=UTF-8&q=dropdown_linkbg.gif
and go through the results to find them.
Note to the author: Cool post but would be cool to add the images too.
Anita Clark Realtor, 14 January 2012
Excellent…I have just the site to try this menu out on.
monika, 20 January 2012
its not working……
Shawn, 24 January 2012
Soh’s personal website is offline at the moment due to domain problems therefore the demo will not be working. Follow him on Twitter to get updates on when his website will be up again:
asisin, 29 January 2012
The menu works well, but I’m running into some z-index issues. The main content container is obscuring the menu so only the first item in the dropdown shows up. Help!
Wayne, 30 January 2012
@asisin – The menu needs to be within the same DIV as your content. Put a container around both the menu and your content, and things should work nicely.
….
…..
Werner, 30 January 2012
Great work with this plugin!
I have an issue when i have loaded the jquery easing js, the dropdowns does not hide properly, but i guess ill find a fix
chris, 01 February 2012
Links to working demo down :(
Emes, 03 February 2012
No demo, please update
Dat4BIT, 03 February 2012
Thank you for the script!!! I just using for a menu with XSL transform. I have a suggest for this use: change this line of JS
$(“ul.subnav”).parent().append(“”);
with
$(“ul.subnav”).parent().append(document.createElement(“span”));
for permit the XSL Transform without problems!
artfanvikram, 07 February 2012
demo link is down, but i made it work for my purpose. Thank you for the tutorial
Aantninyo, 08 February 2012
i think , sohtanaka.com already hacked..its redirecting to 80c.com
Tarkesh, 08 February 2012
Demo page is not working
Ian, 14 February 2012
It sure is, redirects to a kids game site – the demo link! not working!
LKM, 16 February 2012
Are you able to put the demo up on another site/location? be good to see it in action before I implement it..
Sarah, 16 February 2012
Demo page link is jacked.
Sascha, 16 February 2012
Link to Demo is Down….
Joe, 21 February 2012
Demo link still not working…
Frai, 22 February 2012
I use this drop down menu in my webapplication but unfortunately in Internet Explorer it doesn’t always work as it should. After clicking on the trigger, the submenu slides down and after you try to click an item in the submenu a lot of times the submenu just moves back up before your can click on an item in the submenu. This problem only occurs in Internet Explorer not in Firefox. Is there any solution for this problem?
Glen, 24 February 2012
Hey, love this navigation menu, I use it on most of my sites just changing the images and sizes etc. What I’d like to know is how would I go about adding a sub level to an item in the sub menu? A third level sub menu……
Sanjaal, 25 February 2012
The demo is down. I created few images required, minifed the HTML/css and made everything working for me. One of the best examples found. I loved it more than Superfish.
gia vang, 03 March 2012
Can you submit other link demo? the link you send is not work
SMM, 05 March 2012
How can I get the download?
Adva, 07 March 2012
Demo link won’t work as the author’s domain seems to be down?
Please let me know when it’s up again, ty.
Siamak, 16 March 2012
demo link ?
Josss, 19 March 2012
Bad, bad… not working, no link..!
Mohit, 20 March 2012
It looks great. Kindly tell how can I add this to my blog?
Thanks
Daniel, 22 March 2012
Great tut! thanks! No demo still. Is there any way I can get the images?
Ryan Coleman, 23 March 2012
I’ll host your demo, please email me.
Dipender Singh, 26 March 2012
Demo link is going to some other website.
Christiana, 31 March 2012
This is an amazing drop down menu – thank you! The menu to the website I am working on is on the bottom of the page and I need it to slide up. Can anyone please help me make this drop down menu go up instead of down?
Chris, 01 April 2012
The demo isn’t working as about 100 other people mentioned, but I’ll get it to work. Much appreciated for your efforts. Any thoughts on a multi-level drop down menu?
-Chris
Köy Sitesi, 02 April 2012
Very nice.. I got it set up and will be using it often. Thanks!
Jones, 06 April 2012
Round corners also supported in Opera..
Michele, 14 April 2012
The demo link is redirected to an arab website…
SmartBoy, 16 April 2012
Bad name for nice project !
pallavi, 18 April 2012
i want SUB SUBMENU…plz help me
pingshan, 18 April 2012
it’s amazing, i like this style and try to do it in my own blog. thank you!
ss, 10 May 2012
this is does not work at all
Markus, 15 May 2012
is there a way to make the sub menu horizontal aligned?
Amlesh kumar, 22 May 2012
its not working well