This article provides you with easier expanding menu code than a previous article did by losing automatic menu unexpand feature and added some easy CSS code to provide nice mouse over effects.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site

Easier Expanding Menu Code

In a previous article, I described a method to create an expanding menu similar to Windows Explorer, but with only one level of sub-menus. One nice feature of that expanding menu was that when you expanded a menu, the previously expanded menu would unexpand. This helps limit the total length of the menu, but it requires the use of a Java Script array. Every time you expand a menu, the code searches the array for any expanded menus and un-expands them.

Easier expanding menu

Maybe you don't care, or don't desire previously the expanded menu to un-expand. Or maybe you want some easier code and whether the previously the expanded menu to un-expands is a lower priority. In any case, this article provides you easier expanding menu code by losing automatic menu unexpand feature (you need to click to unexpand a menu) and adds some easy CSS code to provide nice mouse over effects.

This example requires three blocks of code, html to create the menu, CSS to expand and unexpand menus and add mouse over effects, and Java Script attached to the html elements onClick events to modify their CSS properties. I promise you that all this code is extremely simple. First let's start with the html. Shown below is code to paste into your webpage to create a menu.

<a class="menu" href="#" onClick="return toggleMenu('1')">
<img id="i1" border=0 src="closed.gif"> Menu 1</a><br />

<span class="submenu" id="m1">
<a class="menulink" href="#">SubMenu1</a><br />
<a class="menulink" href="#">SubMenu2</a><br />
<a class="menulink" href="#">SubMenu3</a>
</span>

This code creates a top level menu. Replace the text "Menu 1" with the title of your menu. This menu contains three sub menu items. In each sub menu line replace the # character with the link for your menu item. You can delete sub-menu lines if you don't need three sub-menu items in your menu. You can add as many sub menu items as you need by simply adding more lines. Note that there is a line break <br /> tag at the end of every sub-menu item line, except the last one.

You can create as many of these top level menus as you need by simply pasting another code block below the ones you already have, but you need to make some minor edits to each new menu, as indicated below.

-  Increment the number passed by the toggleMenu function in the first line.
- Increment the id of the image in the second line, ie from "i1" to "i2".
- Increment the id of the "submenu" span, i.e. from "m1" to "m2".

For example, shown below is the code for the second top level menu.

<a class="menu" href="#" onClick="return toggleMenu('2')">
<img id="i2" border=0 src="closed.gif"> Menu 1</a><br />

<span class="submenu" id="m2">
<a class="menulink" href="#">SubMenu1</a><br />
<a class="menulink" href="#">SubMenu2</a><br />
<a class="menulink" href="#">SubMenu3</a>
</span>

You can add as many top level menus as you want, as long as you increment those three items in the code for each one you add. In each top level menu, you can add or delete as many sub menu items as you need.

Web Design Sections

RSS Feed RSS Feed

Cascading Style Sheets
Understanding CSS Selectors
The CSS Box Model
Understanding CSS Positioning
Add Style to Your Blockquotes
How to Overlay Text on an Image
Display Overlapping Images on Your Webpage
Style Your Imagemap Tooltips
How to Style a List
How to Style a Table
How to Change the Mouse Pointer
How to Use a Starburst on Your Web Page
How to Use a Pull Quote
Easy Scrollable Area Code
Easy CSS Buttons
Create CSS Button Rollovers
Create Custom Horizontal Rules
Easy CSS Popup Windows
Add Drop Shadows to Your Pictures
Easy Text Drop Shadows
Spice Up Your Web Forms with Color and Graphics
Setting a Larger First Letter
Make a Fixed-width Variable-height Round Cornered Box
Easy Visual Effects to Spice Up Your Webpage
HTML, XHTML, and CSS Bible
Web Designer's Reference
Pro CSS Techniques
Code for Horizontal Drop-down Menu Bar
Easy Rollover Menu Code
Easy CSS Tabbed Navigation
Easier Expanding Menu Code
Easy Three-level Expanding Menu Code
Easy Floating Menu Code


[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2009 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269