Horizontal Subnav with CSS
Tags: Intermediate, Navigation
Not too long ago I wrote a tutorial on how to create a drop down menu with CSS & jQuery, today I would like to go over how to create a simple navigation with a horizontal subnav.
In most cases we can achieve this effect purely with CSS, but since we have to attend to our red headed step child aka IE6, we will use a few lines of jQuery to cover all grounds.
Wireframe – HTML
Nest a set of links wrapped within the <span> tag, this is how the sub navigation will be positioned.
<ul id="topnav">
<li><a href="#">Link</a></li>
<li>
<a href="#">Link</a>
<!--Subnav Starts Here-->
<span>
<a href="#">Subnav Link</a> |
<a href="#">Subnav Link</a> |
<a href="#">Subnav Link</a>
</span>
<!--Subnav Ends Here-->
</li>
<li><a href="#">Link</a></li>
</ul>
Styling – CSS

Unlike a regular drop down menu where the subnav appears directly underneath the hovered/clicked list item, in this case all the subnav sets will start at the same location (left aligned – underneath the navigation).
ul#topnav {
margin: 0; padding: 0;
float: left;
width: 970px;
list-style: none;
position: relative; /*--Set relative positioning on the unordered list itself - not on the list item--*/
font-size: 1.2em;
background: url(topnav_stretch.gif) repeat-x;
}
ul#topnav li {
float: left;
margin: 0; padding: 0;
border-right: 1px solid #555; /*--Divider for each parent level links--*/
}
ul#topnav li a {
padding: 10px 15px;
display: block;
color: #f0f0f0;
text-decoration: none;
}
ul#topnav li:hover { background: #1376c9 url(topnav_active.gif) repeat-x; }
/*--Notice the hover color is on the list item itself, not on the link. This is so it can stay highlighted even when hovering over the subnav--*/
Now set the absolute positioning on the <span> tag 35px from the top. I added some rounded corners on the bottom for style (this will not work in IE).
ul#topnav li span {
float: left;
padding: 15px 0;
position: absolute;
left: 0; top:35px;
display: none; /*--Hide by default--*/
width: 970px;
background: #1376c9;
color: #fff;
/*--Bottom right rounded corner--*/
-moz-border-radius-bottomright: 5px;
-khtml-border-radius-bottomright: 5px;
-webkit-border-bottom-right-radius: 5px;
/*--Bottom left rounded corner--*/
-moz-border-radius-bottomleft: 5px;
-khtml-border-radius-bottomleft: 5px;
-webkit-border-bottom-left-radius: 5px;
}
ul#topnav li:hover span { display: block; } /*--Show subnav on hover--*/
ul#topnav li span a { display: inline; } /*--Since we declared a link style on the parent list link, we will correct it back to its original state--*/
ul#topnav li span a:hover {text-decoration: underline;}
For those who are not very familiar with how positioning works, check out the following tutorials:
- w3schools – CSS Positioning
- Absolute, Relative, Fixed Positioning: How Do They Differ?
- Stopping the CSS positioning panic
IE6 Fix – jQuery
Since IE6 does not understand li:hover (basically it only understands a hover event on a <a> tag), use jQuery to go around the issue.
For those who are not familiar with jQuery, do check out their site first and get an overview of how it works. I’ve shared a few tricks that I have picked up along the way, you can check those out as well.
Initial Step – Call the jQuery file
You can choose to download the file from the jQuery site, or you can use this one hosted on Google.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
The following script contains comments explaining which jQuery actions are being performed.
<script type="text/javascript"> $(document).ready(function() { $("ul#topnav li").hover(function() { //Hover over event on list item $(this).css({ 'background' : '#1376c9 url(topnav_active.gif) repeat-x'}); //Add background color and image on hovered list item $(this).find("span").show(); //Show the subnav } , function() { //on hover out... $(this).css({ 'background' : 'none'}); //Ditch the background $(this).find("span").hide(); //Hide the subnav }); }); </script>
Conclusion
Nice and simple! Hope this will come in handy in your future projects. If you have any questions, suggestions, or concerns, please don’t hesitate to let me know!
Related Posts
Author Bio
My name is Soh Tanaka and I am a Los Angeles based designer/front-end developer specializing in CSS driven web design with an emphasis on usability and search engine optimization. I also run a CSS Gallery which is updated daily with the best CSS websites from around the world. Come check it out!
You can learn more about me or
Follow me on twitter for more updates and resources!
Did You Enjoy This Post?
Subscribe via RSS or by email to get all upcoming tutorials and articles delivered straight to you.





+ Add Comment151 Peeps Have Spoken Their Minds...
Why not use nested lists?
Thats really amazing. Thanks for the tutorial.
Nice tutorial, Soh. Menu looks very neat.
@Mariusz My first instinct was to use nested lists, but I thought this way would cut down on markup and was more simple :-)
@janko , marufsiddiqui thanks fellas!
I recently discovered that :hover problem in IE6 and found another workaround. You can use a hover.htc bahaviour for IE6 only. I’ve found at least two different approaches when searching for it again. But I used this in http://www.sjaakpriester.nl/hover.html (it’s in Dutch – but you’ll get it, add extra li.hover class next to li:hover).
@Mariusz, @soh
By coincidence, I’m currently working on a horizontal sub-nav for my site based on nested lists (Joomla makes menus this way).
Positioning the subnav was tricky, especially for a relative beginner like myself, but I got it working somehow.
Instead of jQuery, some simple suckerfish would do the trick for IE6. Of course if you’re already using jQuery on your site then jQuery is fine too, but I wouldn’t install jQuery just to get IE6 hovers working.
@Soh
But it’s far less semantic and could cause annoyance later on if you want to change the navigation style.
It’s nice but I’d rather see it with nested lists :)
ooohh – i like it! clean, tidy and professional – top job!
Fantastic tutorial Soh! You make this sort of thing look so simple.
Thx, Soh, perfect as all the other things too: simple, straight and beautiful. But how would you implement a slight fallback solution if JS is turned off?
I’ve found an interesting article about sprites (http://www.alistapart.com/articles/sprites2) from alistapart. But they used a fixed set of images for there menu structure. But it still works w/out JS.
Do you see a chance to combine both techniques?
Had one question, but with a little testing on my end, I figured out my own answer! :D
Something else I noticed, though, is once you activate the hover state on a menu item, if you don’t move the mouse fast enough, the sub nav disappears before you get to it. Any comments/fixes?
Otherwise, nice work.
Hey, you guys that freely share your time and knowledge CANNOT BE THANKED ENOUGH! Love the presentation of your tutorials… especially the CSS being bundled directly in the HTML file.
I’m a LONGTIME hand coder… extra kudos to a guy that COMMENTS his code!!!
Thanks again for your time, effort, and GENEROSITY!
@deef & Lloyd Vincent – Thanks for the other suggestions! I will def look into them :-)
@Ryan Roberts I agree in that sense, I guess there was a good reason my instinct was poking at me when I created this hehe thanks for your good suggestion~
@fritzek this would work in pretty much all browsers except IE6 and below. No js is needed~
@Mike it may be that you hovered out of the list item which caused it to hide again. There isn’t much that I can think of other than making the hover area larger so people can’t skip outside of it~
@all who commented, made suggestions: thank you :-)
Awesome. I love the simplicity of this. Especially compared to nested lists.
I think it’s much better to create drop-down menus using only CSS and (X)HTML. Like here for example http://www.cssplay.co.uk/menus/drop_examples.html
An afterwards — use jQuery for all fancy shading and sliding.
As a result — you get «Working without js-on menu» and nice menu for peple with js-on.
@Dmitry The only js used on this subnav is for IE6 :-) Maybe I should switch my Title since its maybe misleading
Thanks for the link they have a lot of sweet examples there!! Bookmakred :-)
Hi, i’ve done it with just CSS (no IE6 support) on http://www.klap.com
I understand that the js is solely for stupid browsers (again IE6) support, but should we support that?
Please respect semantic coding first, use double nested s. Nevertheless you provide good example of graceful degradation coding.
i mean: *use double nested uls*
If you wanted to stick with the use of a span (although I tend to agree that nested lists is probably the best way to go about this) you could actually surround the entire list-item content (not the list item itself) with an anchor tag and apply your hover styles to it.
As your spans and links are all inline this will validate well. The only thing you’ll have to do is give the surrounding link an href value of javascript:; (or your favorite “link that won’t do anything when clicked” href value) to avoid any behavioral wierdness that comes from nesting links in links.
The above was in regards to removing jquery completely and still having IE6 support.
Thanks for the tutorial, but I was wondering as I’m not the best jQuery guy – can you do some fading effect to it?
Great tuts…
I used it on my site now, thank you.
nice tut, but
“nested lists”+1
Awesome Tutorial! I think ill use this for the alternate theme I’m Developing for v3 of my site :)
Thank you for sharing!more:http://www.open-open.com/ajax/Menu.htm
This is a great jquery tutorial. I have added it to http://tutlist.com
nice tutorial … as u mentioned earlier u work this for joomla.. so have you made any component or module for this menu ? if so pls i need it …
Is it possible to make that SPAN shows when the link is clicked? (active)?
Thank you!
GOOD JOB.
@Brian Jørgensen Yes you can, check out this tut on how to make it fade in/fade out: http://jqueryfordesigners.com/broken-repeating-animations/ also check out the link below.
@EternalThug if you want it to appear using a click method, you can change the hover to click.
Both of you guys can check out the demo here (its a combination of what both of you were asking for. So try to experiment with it :
http://www.sohtanaka.com/web-design/examples/horizontal-subnav/index2.htm
Thanks for this article, how can we use this one for wordpress category and subcategory
Hey, i love this tutorial, thanks.
Nice work!
Can you please help me in accomplishing the following:
I need to be selected the Main Menu “About” & the sub menu item “The Team”. How can I do this ?
My aaim is to when someone open the page “the_team.php”, then both the About and The Team will be active..
And one more requirement, while moving on other items, show their sub items like current menu.. But after the navigation, the About & The Team will get to be activated.. Is this possible ?
Sorry for the above comment!Love this tutorial!! Thank you!
I have another question. Is there a way that when a visitor clicks a sub navigation link, the sub navigation links remain in place and do not fade away? This will provide the visitor more options under than main category to click on. However, if they hovered over another main nav link..(the top level), then the sub navigation would fade away and be replaced by that new sub-navigation. I hope I was clear on that. Your help would be greatly appreciated. Thanks again!
Hey Soh, the problem with your example from
http://www.sohtanaka.com/web-design/examples/horizontal-subnav/index2.htm
is that it doesn’t work well with Javascript turned off. Maybe have some sort of css backup when the user rolls over it, it will be given the “display: block” CSS property. I’ll look into this for you!
Hi I am using a similar technique for my nav but cant figure out how to keep the sub-nav visible once that sub is active. Can anyone help with this?
Sorry, didnt read previous comments, seems like the question has been asked.
@Joseph.A / bp+
To make a nav have its active state, you will need to associate a body ID (in your case body id =”team” ) and match it with its current list item link class (<a href="#" class="team">The Team</a>). your css would look something like : #team ul#topnav li span a.team {color:red;}
If you want it to be visible by default, you should approach this similar to the tabbing function found in this tutorial: http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/
@Nintensity
Good point! :-) All you have to do then is to add the following:
ul#topnav li:hover span {display: block;}
Thanks~
Hi Soh,
It works..thank you for your quick response. nice tutorials..
If this comment section has a subscribe feature, that will be good.
wow! Awesome!
Hi!
First of all thank you very much for your tutorial, I’ve been looking for something similar for weeks :-S
Although I tried to more or less copy your work with some design adaptations, I can’t manage to make it run in IE8, nor in IE6.
It’s on http://test.pfarreimusik.ch
What am I doing wrong?
Thanks for your support!
buemplizer
Thanks for the article, I will be using this soon.
Hi I’m a second year student and we have a project to do. A website to be made in dreamweaver.. can i put this codes there in css section??
Thanks :)
Thank you so much for sharing your knowledge, this is just the kind of menu I am after!
Thanks for a nice article
awesome stuff!! I want to be able to remove the hover out event so the horizontal sublinks always stay put till you hover over the next main link. I’ve been messing with it myself with not much luck. Any suggestions?
As usually thanks for great tutorial, I will probably use it sooner or later :-)
Great tuts !
But I have two questions :
- how can I have the “subnav” remain for a few seconds after the mouse has left its spot ?
- I would also like to have the “subnav” appear when the page of the corresponding nav is loaded. I tried the homemade code below with no success :
$(document).ready(function() {
$(“span.open_at_load”).show();
}
with added in the html code.
Thanks a lot for your help !
Awesome code, thank you for sharing. I do however have the same request that Jay has above – the need to change the hover out property on the sub navs – so that they stay displayed on hover-out or until another menu item is hovered on. I was hoping it was as easy as deleting “$(this).find(“span”).hide();” but that doesn’t exactly work
Thanks for sharing your code again and please help!
Great tutorial, I’m working to implement it on a design for a current client. It works perfectly!
All the best.
@Will_Powered
This is great. I would also like to know how to have the subnav appear when the page of the corresponding nav is loaded and have it fade when you hover over another link and that links subnav appear.
Thanks!
good menu and similar to the one I’d hacked out myself…but I’ve got a client request that is pretty weird. They want the subnav to appear on hover, but also STAY when the user clicks on one of the nav items in the top nav. So, work this way on hover, and another way when the user clicks. I can’t for the life of me figure this out. any ideas?
Thanks! Added to my design favourites!
Personnally I would use nested lists, wouldn’t that help a tiny bit in SEO?
Hello, very interesting example.
I wonder if there is a way to insert a second (vertical) submenu, a menu from the subnav.
example, a list of members that appears below the “team” in “about”.
thanks mate, this is a great tut. thanks for sharing … anyway :) .
hm… I don’t but people blinds can use it easy?
I like. How would you make it vertical?
nice beautiful work ! i have added it in my favorites.
could you also give some referenct to learn the JQuery.
Thanks,
Use the jquery hoverIntent plugin to avoid the annoying issue of the hover being cancelled if you move the mouse too slowly or accidentally roll off of the hover trigger.
Also, you *really* should use nested ul’s for this.
To the previous suggestion of nesting the secondary ul’s *inside* of the anchor.. you can’t do that. It won’t validate and will almost surely cause problems in many browsers. Links shoudn’t contain block level markup and should *never* contain another link within it.
Não entendi nada.
Nada!
Great tutorial man. Thanks a lot !
awesome tutorial thank you.
Amazing,
i love your menu and i want to add this in to my templates,
So what license its?
thanks
Abba Bryant – how did you implement the jquery hoverIntent plugin?
Thanks a lot for this post. I really like your site. You make use of a lot of great css and javascript tools.
Thanks for the tutorial. I like your sites design too. Ive just realized after reading through your comments that I can probably find a nested list solution for my horizontal subnav in wordpress, but if anyone is interested, I wrote a little jquery to convert nested lists (wordpress pumps out with wp_list_pages) into the span type list you have used.
http://www.pastie.org/630365
really awesome thanks for sharing. M
I second Wallaces’ question. Anyone know a way to place a third level vertical menu triggered from the sub level span links? that would be awesome.
[wallace
Hello, very interesting example.
I wonder if there is a way to insert a second (vertical) submenu, a menu from the subnav.
example, a list of members that appears below the “team” in “about”.]
i think, well done ;)
thx a lot for publishing!
I love the tuts on this site. Very helpful, bookmarked :-)
I am also trying to find out how I can have the submenu stay active.
I read all the comments and your suggestions, particularly this comment of yours:
[quote]@Joseph.A / bp+
To make a nav have its active state, you will need to associate a body ID (in your case body id =”team” ) and match it with its current list item link class (The Team). your css would look something like : #team ul#topnav li span a.team {color:red;}
If you want it to be visible by default, you should approach this similar to the tabbing function found in this tutorial: http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/
[/quote]
The problem I have is that when I click on a submenu, let’s say “Team”, and go to the actual “team.html” page with a , I can make it active as you proposed with this code: #team ul#topnav li span a.team {color:red;} BUT I have to hover over it on order for it to appear. I want to have the submenu active with the actual “team” button active as well.
I read your “Tabs” tutorial, and don’t understand how I can adapt the code to make it work when it actually navigates away from the main page to another html page, vs. just switching back and forth between the tabs.
Don’t know if this makes sense, so here is a link to a screenshot of my desired navigation:
http://img97.imageshack.us/img97/9771/navit.png
it seems to be a combination of CSS sprites for the main navigation, and of the other two tutorials of yours for the rest…
help appreciated: salvia{at}gmx{dot}li
@Soh
Really nice tutorial!
FYI: I think your comment box resizer is broken in Chrome.
@All
For anyone that has to work with menus that contain nested uls instead of the structure Soh uses (for example, I’m using Joomla) just change Soh’s css code; wherever he has ‘span’ replace it with ‘ul’.
If you’re using nested uls you will most likely also want to set ‘list-style: none;’ for ‘ul#topnav li ul’.
Wow.. what a great menu. Is there any way to have seperate colours for each drop down menu????
E.g. green for one, red for another, and blue for another etc.
Hi,
I have got this to work in wordpress. change the style as below:
body {
font: 12px normal Verdana, Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
}
h1 {
font: 4.7em normal Georgia, ‘Times New Roman’, Times, serif;
color: #333;
margin: 0;
padding: 5px 0;
}
h1 small{
font: 0.2em normal Verdana, Arial, Helvetica, sans-serif;
text-transform:uppercase;
letter-spacing: 1.5em;
display: block;
color: #fff;
}
.container {width: 970px; margin: 0 auto;}
ul#topnav {
margin: 0; padding: 0;
float: left;
width: 960px;
list-style: none;
position: relative;
font-size: 1.2em;
background: #000 url(topnav_stretch.gif) repeat-x;
}
ul#topnav li {
float: left;
margin: 0; padding: 0;
border-right: 1px solid #555;
}
ul#topnav li a {
padding: 10px 15px;
display: block;
color: #f0f0f0;
text-decoration: none;
}
ul#topnav li:hover { background: #1376c9 url(topnav_active.gif) repeat-x; }
ul#topnav li ul {
float: left;
padding: 15px 0;
position: absolute;
left: 0; top:35px;
display: none;
width: 960px;
background: #1376c9;
color: #fff;
-moz-border-radius-bottomright: 5px;
-khtml-border-radius-bottomright: 5px;
-webkit-border-bottom-right-radius: 5px;
-moz-border-radius-bottomleft: 5px;
-khtml-border-radius-bottomleft: 5px;
-webkit-border-bottom-left-radius: 5px;
}
ul#topnav li:hover ul { display: block; list-style-type:none; margin: 0; padding:10px 0; }
ul#topnav li:hover ul li{ display: block; }
ul#topnav li ul li a { display: inline; }
ul#topnav li ul li a:hover {text-decoration: underline;}
Then do the the call in the page:
Then edit the IE6 script:
$(document).ready(function() {
$(“ul#topnav li”).hover(function() { //Hover over event on list item
$(this).css({ ‘background’ : ‘#1376c9 url(topnav_active.gif) repeat-x’}); //Add background color and image on hovered list item
$(this).find(” ul “).show(); //Show the subnav
} , function() { //on hover out…
$(this).css({ ‘background’ : ‘none’}); //Ditch the background
$(this).find(” ul “).hide(); //Hide the subnav
});
});
What would the proper mark up be to implement this menu technique into WordPress? Thank you for the great work!
Just add this code to your navigation bar in the header.php for your theme.
//to add pages
//to add categories
<a href=""> Home
Great tutorial. Thank you for the info!
Hey! How can I successfully add it to an already made page ?
I seem to screw up somewhere, it ends up as a dotted list and is really butt-ugly =)
I must be misplacing the codes …?
Thanks.
Lovely, just what I was after. Still tinkering with it for my site but will definitely be using it, thanks.
Is it possible to create the second level nav without the use of the span?
I’m using the thematic framework for wordpress which doesn’t allow for inserting the span for each subnav. I’ve been playing with the above css but the results have been highly undesirable.
OMG, this is an awesome tutorial. I’m going to use this on my next design.
Just an update: I managed to get a horizontal nav working with Thematic using a different solution (http://themeshaper.com/forums/topic/create-horizontal-dropdown-child-menu-that-holds-on-subpage) for those who are interested.
Excellent, works a treat. I was looking for a menu like this for a project I was doing – works perfectly and takes into account the usual IE quirks as well. Thankyou!
A few others asked, so I thought I’d throw my hat in the ring. I too am looking for a way to make a vertical submenu (under the current item top-tier nav).
I’m racking my brain looking for the simple solution!!
Nice, nice, nice… Great job!!!
Thanks for the article. nice tutorial
Génial et comment on fait pour que ce menu se déroule vers le haut???
Perfect! I think the use of span tags makes this approach much more flexable than ul li hierarchies.
it’s perfect,however,this can’t highlight the selected item
Very great tutorial, I am using it now in my project but I have a question.
Is any chance to align submenu right under the related buttom? for example if I press in “About” the submenu “The Company” start from “About” level and not from the left like it does now.
Thanks in advance
Javier
Wel I just could make it, if is anybody interesting out there, here is the solution:
Add class to the span, ex:
About
The Company
The Team
and then with css:
ul#topnav li span.second a {
position: relative;
left:120px;
}
Thanks anyway,
Javier
Sorry Tanaka san, I forgot to use the “Postable”
Here is the html code:
<li><a href="" title="About</a>
<span class="Second">
<a href= "#">The Company</a>
<a href= "#">The Team</a>
</span>
</li>
Javier
I have to learn a lot in css :(
good work, its a nice and easy to understand kinda tutorial..
kepp it up..
:)
Thank you very, very much for this excellent tutorial! I didn’t have to do that much tweaking to get it to work on my site.
The only thing is I haven’t been able to center the menu.
I tried adding “text-align: center;” to #topmenu, but it only centered the sub-menu. Any help would be greatly appreciated! Thanks!
Soh, thank you very much for this great tutorial – this is fantastic and has helped me a lot in a recent project I had to complete at work.
I have a general question regarding CSS though:
You’ve specified your styles as follows:
ul#topnav li span
What is the difference between specifying it like that and this:
#topnav ul li span
Does this achieve the same thing?
오 너무 좋은 자료네요! 감사합니다^^
I’m Korean!
Thanks for the information!
If you already have a mechanism for giving the li containing the active link a class=”link” (I’m using Joomla and its a built in feature), you can keep your submenu on the active page displayed while having the other submenus visible on hover by setting your z-index like so:
ul#topnav li:hover, #header .main ul li.active {
background: #1376c9 url(topnav_active.gif) repeat-x;
}
ul#topnav li:hover ul{
z-index: 100;
}
ul#topnav li.active ul{
z-index: 0;
}
ul#topnav li:hover ul, #header .main ul li.active ul {
display: block;
}
ul#topnav li:hover ul a, #header .main ul li.active ul a {
display: inline; /*–Since we declared a link style on the parent list link, we will correct it back to its original state–*/
}
Might not be totally semantic or work in all situations but it seems to work well so far. Oh and I used nested lists instead of the span tag for this, but Im sure it would work just the same.
I meant for the last two style definitions:
ul#topnav li:hover ul, ul#topnav ul li.active ul {
display: block;
}
ul#topnav li:hover ul a, ul#topnav ul li.active ul a {
display: inline; /*–Since we declared a link style on the parent list link, we will correct it back to its original state–*/
}
Sorry about the confusion.
Nice tutorial. I’m new to web design and just wanted to know how you got your graphics for this sub navigation? Did you use PS or FW?
Thanks
Hello, you’ve done such a good work. I have one question, does anobody know how to use this menu in asp.net master page ? Is it possible to persist postback and after postback the menu will be still higlighted on selected menu.
Thank you,
Regards Vasek
Thanks for a wonderful tutorial! How can I align the entire navigation bar in the center?
Thank very much for this, I played with the style quite a bit and came up with this:
http://jamesspratt.org
Cheers,
James
This example really helps me alot…thanks so much :)
@James Spratt. org
Hi James! I have seen your page. really cool. Can you give the JavaScript-Code that you use for navigation on youu page?
Almost pure CSS navigation. Maybe now in the year 2010 we can start making it pure css by ignoring IE6…
Anyways, it’s better for SEO because search engines can crawl it. Thanks for sharing
hey thanks for the nice share.. i have a little problem with it when i add this code into my page, the code for border rounded corners do not work properly can you please tell me that how it will work
thanks again….
Nice, but not sure why you need jQuery for this, it can be done easily with pure CSS and nested lists. Adding jQuery is overkill in my humble opinion.
@James Spratt
I hate to say it but that nav menu on your site looks a bit of a mess. When a sub-menu wraps to another line, it looks… gay. It looks too unorganized.
Hi,
Thanks for a nice dropline menu.
Is it possible to change the color of the main menu when it is active. i.e When its sub levels are shown.
Please help me.
I love you right now, lol I have been looking for this all day today… You just made my day!
Awesome tutorial, code to have the top tab stay on when clicked, menuID is the id of the selected tab..
<script type="text/javascript">
var selected = "menuID";
$(document).ready(function() {
$("ul#topnav li#" selected).css({ 'background' : '#1376c9 url(img/topnav_active.gif) repeat-x'});
$("ul#topnav li#" selected).find("span").show();
$("ul#topnav li").hover(function() { //Hover over event on list item
$(this).css({ 'background' : '#1376c9 url(img/topnav_active.gif) repeat-x'}); //Add background color image on hovered list item
$(this).find("span").show(); //Show the subnav
} , function() { //on hover out…
if (this.id != selected) {
$(this).css({
'background': 'none'
}); //Ditch the background
$(this).find("span").hide(); //Hide the subnav
}
});
});
</script>
@otto Thanks mate, have tweaked it a little more. No js is used with mine.
@dogboy My cross-browser checking is not what it should be. Whatever you looked at it in should be fixed now. Any less gay for you now?
I love these jquery tutorials working for me need to know this stuff
great stuff man
thanks for the share
HI, good script, but in IE there is a white space between ul and li and when pointer is in it the submenu disappear. Why?
I’ve resolved changing this section: left: 0; top:33px;
Thanks
Thank you for this, good tutorial :)
this is really very helpful and working tutorial… Thanks man and keep on going.
I got this working in seconds… I changed the spans with uls and still works like a charm.
Thank you so much for helping the newbies…
It’s good! tks
Very Cool, looks like it’s perfect for my next project. I am using the 960.gs framework, any tips to keep it consitant with the framework?
Wow, One of the neat and clean tab menu i saw in CSS
Took a few days to find this excellent tutorial, obviously looking in the wrong place. I have changed colours to suit website but would of liked the second Navbar to stay on all the time. Probably a few tweaks in the CSS and it will be done. It Now uses a nested list so should now work with any website without changing the structure.
Thank you for this, will save you in my favourites and come back and see what else you have done to make my life easier.
I can’t make the JS work on IE :(
Hi
Love the navbar but how do I get it to work like your one above (latest word etc). I’d really like the subnav to stay when clicked on so I can see it on the relevant pages? Sorry if I’m asking a question that’s been asked already – I’m new to all this and got quite excited when I got it working! Thanks again.
So how do you get this to work in a master page?
Hello Soh, I first wanted to say thanks for the tutorials. They have been extremely useful, however, I’m having some difficulty getting the active button to function.
I’ve developed the navbar as advertised but it fails to perform the necessary action needed to do the following.
Maintain an Active state. Maintain active state when subnav is activated.
Test site can be found at http://rose.stedic.ca
It’s
Thank you, thank you, thank you!!! This just totally saved my bacon. I’m swamped with a project for a client who’s IT staff is too lazy to upgrade them past IE6!
I used this and I love it but I ran into two problems. 1), the subnav background color doesn’t show up in Firefox and the menu doesn’t seem to work at all in Chrome. =(
Hi Soh, really love this one!
Have you done any examples where you combine the image based rollover li nav you used on the VestaxSpin site, but add a bottom tier sub level which is purely text based as you did above?
I am trying work these two type of approaches together with no luck!
So to confirm:
Image 01 :: Image 02 :: Image 03
Text Link | Text Link | Text Link
Does that make sense?
First: Thank you so much for your entire website, helped me a lot!
Im a newbe,… but maybe I got an easy solution for those who want the active subnav to stay visible after leaving the topnav. I added a CSS class “active” and did some jQuerry which does the trick for me:
//jQuerry Script
$(“ul”).mouseover(function() {
$(“li”).removeClass(“active”)});
$(“ul li”).mouseout(function() {
$(this).addClass(“active”)});
add this in CSS side
ul#topnav li.on a {background-color: #1376c9}
and tag li class on in HOME…hihihihi
Hi,
I want to know how can I change the width of the blue strip of the submenu, i want it to be thinner. I can see in the ul#topnav code that you can specify the width, but I tried coding in the height, but it didn’t work.
Well done!!! It´s perfect!
I am so close to throwing something out my pram.
I would be quite content with this implimentation if it wasn’t for the really naff feedback bug that Matt reported like a year ago where if you aren’t some kind of mouse ninja you can lose the sub nav.
I didn’t understand the comment on increasing the padding. Padding of what? the li a? that’s just going to make the topnav row higher, it isn’t likely to detract from the underneath. I’ve even tried setting the span z-index to a negative to get it to clip underneath the topnav thinking this may allow for an overlap but nope. nada.
Has nobody else really solved this brainache?
Fantastic tutorial!! I am going to use this a lot~! It is different than the traditional dropdowns
One question. I am attempting to have different text colors. red on silver bg and then white text on red bg on hover. when I hover off the top li links they go back to red and blend in the bg. Anyway to make it so that while scrolling through the span list I keep the li a the white?
Hope my question was clear. thanks for the help.
Great tutorial, very easy to follow. I’m a bit surprised you went out of your way to include the IE6 – appreciative, but surprised nonetheless. Thanks!
Is it possible to adjust the horizontal padding of the topnav menu items without affecting the lower subnav span items? Currently they seem to be interconnected. I want to have the topnav items to have a horizontal spacing of 30px and the lower subnav to have only 15px spacing.
ul#topnav li a {
padding: 10px 30px;
Someone mentioned about the submenu stay for x seconds, but no answer came.
Someone an idea ?
sorry man but really i didn’t understand how to put the subnav to my site
as where i put the codes above
this was really awesome.. i ws trying o do this for past 4 days..thnx very much…
Just wondering where the images are if we’d like to use your code? Also, the nav bar is invisible in all browsers I tried it in…any suggestions?
Not customizable ? Thanks for showing such fantastic work. Kids it will be usefull.
Please Beatiful people, i saw this awesome tutorial this and i like it too much. But implementing it, all the “span a’s” are squeezing together in place and not lining out horizotally. What should i do? Please help me.
Best Regard
Ronny
Nice! it helpful for all
Please do you how i can solve this problem i am facing? All the “span a’s” are squeezing together in place and not lining out horizotally. What should i do? Please help me.
Best Regards
Ronny
Hi, guys, this is great for me to learn about the tabs, I’m currently want to add menu using only .css and no .js, i have tried taht from
http://www.cssplay.co.uk/menus/drop_examples.html
and for some reason is not working, does any one have tried this! if so can any one provide me sample code of this menu with with tabs for myself to learn please.
AM
Hi SOH,
I’m new to jQuery & CSS. How do you combine Horizontal Sub-nav with CSS & Simple Toggle with CSS & jQuery? I’ve tried every way possible but wasn’t successful. Any suggestion on how I can combine the two?
Speak Your Mind...