1. Home
  2. Computing & Technology
  3. JavaScript

Double Bar Menu

3. Stylesheet

Join the Discussion

Questions? Comments?

More of this Feature

Introduction HTML JavaScript

With an operational navigation menu in our page, the next step in making it into a double bar menu is to apply some styles to the menu in order to make the entries actually appear as a bar across the page.

To do this the first step is to copy the following stylesheet code and save it as bmenu.css.

body {margin:0; padding:0;}
#nav ul {margin:0; padding:0;list-style: none;
position:absolute; border: 1px solid #ccc;
background-color:#99f;
width:100%;}
#nav li {float: left; width: 10em; height:1.2em;}
#nav li a {color:#fff; text-decoration:none;}
#nav div {position:relative; top:1.3em; height:2em;}
#nav div ul {display:none;}

Next you need to modify this code so the menu looks the way you want. Those things that you can safely change are the border, background-color, color, and the width of the li. You should leave the rest of the code alone or the manu will not display properly as a bar across the page.

To apply this stylesheet to the menu we link it into the head of our web page.

<link rel="stylesheet" href="bmenu.css" type="text/css" />

Our menu should now appear as a single bar across the page with a gap under it. The entries should be functional to take people to the pages that you want them to see if they have JavaScript disabled.

Of course if they do have JavaScript then we want the menu to function differently with the links on this menu bar determining which second bar to display below it. To achieve this we need to add the JavaScript.

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.