Your Ad Here

CSS tabs with Submenus

There’s lots of talk recently about creating tabbed menus with CSS, but very little about associating submenus to the tabs. Joshua Kaufman and Richard Rutter have done it, but their methods require the creation of separate unordered lists that are only associated with the parent menu by the CSS. If you view the page without the stylesheet — with a screen reader for example — the navigation is confusing and impossible to decipher.

I created a method of adding submenus to your tabbed navigation in which the submenu lists are nested into the parent navigation list list. So anyone not using CSS will see a menu that looks like…

  • Home
  • About Us
    • People
    • Careers
  • Contact Us

… and everyone else will see a tabbed menu like …

Screen capture of CSS tabs

I’ve put up a demo page for your enjoyment.

Update: I forgot to mention: please feel free to use the code and mangle or adapt it as needed. If you use it would be nice if you’d tell me where. I’m just curious where it ends up.

trimble
April 4, 2006 10:16 AM

Being a CSS newbie, I’m still trying to figure out how this magic works! How does the passed url translate into a different body class? Although the demo seems to be a single page, its tabs can be referenced with distinct urls. I’ve also looked at other sites listed here where the content changes from tab to tab.

Amazingly cool stuff, but I could really use some help in understanding it before I’ll be able to implement it.

Thanks!

Alan
April 17, 2006 11:07 PM

Trimble: in case you haven’t figured it out, it actually is different pages but only the id on the body tag is different.

chaitanya
May 2, 2006 2:22 AM

hi, i’ve been working on a project for which i was testing whether tabs (in a form for html)work for various browsers.it works fine for IE but for netscape(6.1 &6.2)the use of the tab key doesn’t seem to work.is there any wokaround or any authenticated document supporting this?any pointers are appreciated.

gutielua
May 15, 2006 11:54 AM

Hi!

Your CSS Tabs Rocks!

One question, what I need to do to remove the underline for all buttons? Only I want a rectangle, witout underline.

Tnx in advance!

Regards from Monterrey, México.

@ndrés

trimble
July 28, 2006 11:26 AM

Thanks Alan,

Yes, I did eventually figure out how the body id tag controlled the menu’s style. I’ve implemented the menus inside of Div containers and control the their style that way. I love the flexibility and scalability of the menu, but do have a couple of new questions, though.

Is it possible to position the subnav links so that they are relatively positioned to the tabs? Their absolute positioning has been a real pain in the neck for me, as I’d like to use the menus across pages with different side and top margins.

Also, has anyone been able to adapt this css to function as a dropdown menu? CSS-based dropdowns I thus far seen are not nearly so elegant or scale so well as Adam’s, and they don’t degrade well on browsers with limited CSS support (like most PDAs).

Cheers!

allgood2
August 1, 2006 12:44 PM

Hi Adam, Love your tabs and especially the sub-navigation. I’m implementing them on a client’s site, and things look great. I had just one issue: controlling where the sub-menu starts without absolute positioning.

View Test Site http://www.consumer-action.org/housing/test_navigation/ The site layout isn’t fully flexible. Basically, the center container has a defined width, and everything else floats. For the sub-navigation, I removed the absolute {left: 10px; } and the menu kind of floated; but irritating enough, didn’t start until after the main-tab that it was associated with.

I played around with a variety of elements before finally giving the display property: block; a go. This seemed to work, except with some Internet Expolorer issues. Or I should say, it displayed properly on Mac OS X 10.4.x under Safari, Camino, Firefox, and Shiira, and it also displayed properly on Windows 2000/2003 with Netscape 7.2, but only adequately under Internet Explorer 6.x.

I’m no CSS guru. I’m fairly compotent at composing stylesheet; but still only have a basic understanding of why some rules work or don’t work in various situations. I’m wondering if you can think of any “gotchas” from my current approach, versus using your absolute positioning. The site is one of a series of sites, and all of them are contained in a center float, so I’d rather not tie this one down to absolute positioning just to get the navigation items working.

Thanks.

Carsten Kollmeier
February 9, 2007 12:39 AM

Hi!

Your tabs navigation is exactly what I was looking for, thanks!

But I figured out some more: To do an easier positioning of the submenu, I put the whole tab-menu into a div-container with the property “position: relative”. Now all enclosed tags with the property “position: absolute” are positioned relatively to the enclosing div. For explorer to work, you have to give the uppermost ul the property “position: static”, because explorer otherwise seems to inherit the “position” property from the enclosing div.

Furthermore I enhanced your menu to allow some javascript navigation.

See yourself at http://neu.nabeba.de

I’m planing to document this stuff a bit more understandable as soon as I find the time.

JM
February 22, 2007 3:20 PM

Your Tabs Rock!

Carsten Kollmeier
March 12, 2007 7:07 AM

Hi again!

Unfortunatly the javascript-enhance tabs-navigation I mentioned two posts before is not found under the old URL.

This is because it’s the location where I test new stuff before implementing it at the live site. IF you are interested how the javascript stuff looks like: http://www.nabeba.de .

Still, I did not find the time to write a brief tutorial.

youn
May 4, 2007 10:58 AM

i saw some of these tabs on a jeans and clothing website luxuriousgear.com

Vent Swap
May 4, 2007 5:40 PM

I’ve tried your demo but it breaks up in IE7

Jon
June 14, 2007 6:11 PM

Am about to embed your tabs (sans sub-menus) in a brand new time-clock product — you know, the kind in so many warehouses that employees use to punch in / out. The clock features an embedded web server. The product is distributed through major retailers (e.g. Best Buy, Costco, etc.). If it passes our cross-browser testing, it ships ;-)

Good work on keeping things simple and elegant. Thanks.

IE7 Fix
June 18, 2007 2:39 AM

To make the submenus look good in IE7, change the css rules that go:

body.section-1 #menu ul#subnav-1, etc.,

change: top: 95px

to: top: 100px.

Obviously, this will change the way things look in other browsers, so this is not the final solution. Hopefully someone will be able to use this lead to fix the stylesheet.

Avinash Kachhy
August 29, 2007 2:20 PM

I am trying to display a div a ta time on a single html page using css tabs and a javascript function to unhide the correct div and hide the other divs. It works fine but the first time the page loads, all the tabs are in the inactive style. I cannot use the body style for showing the correct active tab. I need to have the left most tab show as active when the page loads but behave as any other tab once any other tab is clicked. I tried generating a click event to change the background on load event, etc. but the display is not affected. Any help will be appreciated. Thanks.

E_McC
February 1, 2008 4:28 AM

I am trying to re create the tabs but only want the sub nav as the main nav. I want to know what type of files as the tools/csstabs/1 , /2, /3 and /4? are they just seperate CSS files? Also I don’t want to go to a new page everytime you click one of the buttons. I just want the text to change?

Could you help me out with this matter?

Thanks

These are the last 15 comments. Read all 111 comments here.


Your comments:

Text only, no HTML. URLs will automatically be converted to links. Your email address is required, but it will not be displayed on the site.

Name:

Email: (not displayed)

If you don't feel comfortable giving me your real email address, don't expect me to feel comfortable publishing your comment.

Website (optional):

Lijit Search

Best Of

  • Customer reference questions. Sample questions to ask customer references when choosing a software vendor.
  • Embrace the medium The Web is different than print, television, or any other medium. To be successful, designers must embrace those differences.
  • Lock-in is bad T-Mobile thinks they'll get new Hotspot customers with exclusive content and locked-in devices.
  • Writing Realistic Job Descriptions Publish a job listing like this one and you are virtually guaranteeing that you won't get qualified applicants for the position.
  • Newly Digital Newly Digital is an experimental writing project. I've asked 11 people to write about their early experiences with computing technology and post their essays on their weblogs. So go read, enjoy, and then contribute. This collection is open to you. Write up your own story, and then let the world know about it.
  • More of the best »

Recently Read

Get More

Subscribe | Archives

Recently

Sprout Test (May 7)
A test post for Sprout widgets.
Product Leadership (May 3)
An anthology of product leadership writing.
Fighting Monster patent claims (Apr 16)
The patent bully picked on the wrong little guy.
Peavy's pine tar (Apr 6)
Jake Peavy's cheating
Bush and Morgan on inner city baseball (Mar 30)
Morgan and Bush discuss the role of baseball in the inner cities.
Not a fork (Mar 27)
We have no intention of forking Drupal. That would be nuts. So what are we doing then?
Eating our dogfood in the sausage factory (Mar 26)
Recursive development for the new Drupal powered community platform.

Subscribe to this site's feed.

Elsewhere

Feed Crier
Get alerted by IM when your favorite web sites and feeds are updated.
SacStarts
The Sacramento technology startup community.
Pinewood Freak
Pinewood Derby tips and tricks
Del.icio.us
My tagstream at del.icio.us.
Waddlespot
My son's Club Penguin community. News, blogs, tips, and tricks.

Contact

Adam Kalsey

Mobile: 916.600.2497

Email: adam AT kalsey.com

AIM or Skype: akalsey

Resume

PGP Key

©1999-2008 Adam Kalsey.
Content management by Movable Type.