minitutorials main logo the place to learn online

Sponsor This Site!
Sponsorship Details - miniTutorials is taking enquiries into various Sponsorship opportunities. Available NOW! Read More on our Sponsorship page.
This Page Sponsored by :
Proudly Sponsored by Your Company name here!
miniTutorials Sponsorship
Donate!
Consider donating to keep this site alive and up to date. Click on the Donate button to go straight to PayPal site and make a donation of an amount you choose.


More information on where the money goes on the Donations page.
Discussion Forums
visit the mini tutorial forums
For expert help and advice on any of our Tutorials or anything else .... visit the forums and ask away!!
Google Ads
My Profile

Details about the owner of this site can be found at :-

ohloh profile
View Gavin McDonald's profile on LinkedIn
Powered by a
UK2 Dedicated Server

CSS Menus

Creating a CSS driven Menu system - Part 3 - By Geoff Vines

Going horizontal

If you have the need for a horizontal menu rather than a vertical one, there is not that much you need to do different.  The basic principles still apply.

The actual menu structure remains completely unchanged.  Its all in the css coding.

Before we start, get rid of the spoiler <div> and its styling code.  It's served its purpose.

First we need to add code to the level 1 <ul> so that it is wide and narrow, thus constraining the <li> elements.  And we need to float the <li> elements so that they follow each other in a line instead of stacking up on top of each other.

Note that we have removed the border-bottom: none; and the width: 80px; instructions.

   div#navigation ul {
      list-style: none;
      list-image: none;
      margin: 0;
      padding: 0;
      position: absolute;
      border: 1px solid #000;
      background-color: #C8C8C8;
   }
   

   div#navigation ul.level1 {
      width: 500px;
      height: 25px;
   }
	
Here border-bottom has become border-right and we have added the float: left; instruction.

   div#navigation ul.level1 li {
      position: relative;
      border-right: 1px solid #000;
      float: left;
   }
	

We also have to make some tweaks to the sub-menu which includes changing the offsets of the sub-menu so that it appears correctly relative to its parents new position.


   div#navigation ul ul {
      position: absolute;
      display: none;
      border-bottom: none;
   }
   

   div#navigation ul.level2 li {
      border-bottom: 1px solid #000;
   }
	

   div#navigation li.submenu:hover ul.level2{
      display: block;
      left: 0px;
      top: 19px;
   }
	

   div#navigation li a {
      display: block;
      padding: 3px 0 3px 3px;
      text-decoration: none;
   }
	

This all results in a display like this:

img5 (1K)

Note that the 'Services' menu item still needs some styling work and you will find you can't reach the sub-menu to keep it displayed.  This is because the height of the 'Services' <li> is not the full height.

But you can fix this - can't you?

You now know all the basics of producing a pure css driven dynamic menu, either vertical or horizontal.  How you style it, size it, place it in the position you want on the page are up to you.

You can also extend the process to have sub-menus of sub-menus.

This tutorial is also available in a PDF version.
This tutorial is Part Three of a Three Part Series and was written by Geoff Vines from 1ontheweb .

Related Tutorials

Part One - The basic building blocks.
Part Two - Adding Styling.

Top

tutorial sponsors logo

About Us | Site Map | Privacy Policy | Contact Us | ©2002 - 2007 miniTutorials.com