1. Home
  2. Computing & Technology
  3. JavaScript

Double Bar Menu

2. HTML

clr gif
Join the Discussion

Questions? Comments?

More of this Feature

Introduction Make Your Menu

The first step in adding a double bar menu to your web page is to write the HTML for the menus. As a navigation menu is basically a list of links, that's how we will code it in our HTML.

Here is my sample HTML for the menu. You can of course add as many more menu entries to each bar as you need and add additional versions of the second bar for each additional entry in the top bar. You will also need to change each of the links to actually point to the appropriate web page. In the case of the links in the top bar you will want to point them to pages that will provide access to the pages in the second bar menus for those of your visitors with JavaScript disabled.

<div id="nav">
<ul>
<li id="menu1"><a href="#">Option One</a></li>
<li id="menu2"><a href="#">Option Two</a></li>
</ul>
<div>
<ul id="n1"><li><a href="#">Option 1A</a></li>
<li><a href="#">Option 1B</a></li>
<li><a href="#">Option 1C</a></li>
</ul>
<ul id="n2"><li><a href="#">Option 2A</a></li>
<li><a href="#">Option 2B</a></li>
<li><a href="#">Option 2C</a></li>
</ul>
</div>
</div>

Note that the div wrapping the entire menu must have an id of nav in order for the menu to be styled correctly. The li tags in the first menu must have ids of menu1, menu2 etc with the corresponding ul tags for the alternate second bar menus having ids of n1, n2 etc where the numbers match between the entries so that the JavaScript knows which menu belongs to which option. The div around all the second level menus is also required for the stylesheet to work correctly.

With this in our page where we want the menu to appear our page is now usable even for those whose browsers cannot handle stylesheets even though the menu looks nothing like the actual bar menu that we want people to see. The next step is to add the stylesheet to make the menu actually appear as a bar across the page.

Introduction | HTML | CSS | JavaScript
Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.