HTML
  Home arrow HTML arrow Page 2 - Building a Drop-Down Menu with Nested HTML...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
HTML

Building a Drop-Down Menu with Nested HTML Lists
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2009-05-29

    Table of Contents:
  • Building a Drop-Down Menu with Nested HTML Lists
  • Start building a drop-down menu: the structural markup
  • Using CSS styles to turn the menu into a functional user interface
  • Making the menu compatible with Internet Explorer 6 and below

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building a Drop-Down Menu with Nested HTML Lists - Start building a drop-down menu: the structural markup


    (Page 2 of 4 )

    The first layer that I'm going to define to build the drop-down menu is the one that comprises the menu's structural markup. Essentially, this particular layer will be made up, not surprisingly, of a few nested lists, which will include the corresponding links.

    Having explained that, please take a look at the following sample code, which creates the bare bones structure of this drop-down menu. Here it is:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Drop-down menu using nested lists</title>

    </head>

    <body>

    <ul id="navbar">

    <li class="topitem">Top Item 1

    <ul>

    <li><a href="#">Sub Item 1</a></li>

    <li><a href="#">Sub Item 2</a></li>

    <li><a href="#">Sub Item 3</a></li>

    <li><a href="#">Sub Item 4</a></li>

    <li><a href="#">Sub Item 5</a></li>

    </ul>

    </li>

    <li class="topitem">Top Item 2

    <ul>

    <li><a href="#">Sub Item 1</a></li>

    <li><a href="#">Sub Item 2</a></li>

    <li><a href="#">Sub Item 3</a></li>

    <li><a href="#">Sub Item 4</a></li>

    <li><a href="#">Sub Item 5</a></li>

    </ul>

    </li>

    <li class="topitem">Top Item 3

    <ul>

    <li><a href="#">Sub Item 1</a></li>

    <li><a href="#">Sub Item 2</a></li>

    <li><a href="#">Sub Item 3</a></li>

    <li><a href="#">Sub Item 4</a></li>

    <li><a href="#">Sub Item 5</a></li>

    </ul>

    </li>

    <li class="topitem">Top Item 4

    <ul>

    <li><a href="#">Sub Item 1</a></li>

    <li><a href="#">Sub Item 2</a></li>

    <li><a href="#">Sub Item 3</a></li>

    <li><a href="#">Sub Item 4</a></li>

    <li><a href="#">Sub Item 5</a></li>

    </ul>

    </li>

    <li class="topitem">Top Item 5

    <ul>

    <li><a href="#">Sub Item 1</a></li>

    <li><a href="#">Sub Item 2</a></li>

    <li><a href="#">Sub Item 3</a></li>

    <li><a href="#">Sub Item 4</a></li>

    <li><a href="#">Sub Item 5</a></li>

    </ul>

    </li>

    <li class="topitem">Top Item 6

    <ul>

    <li><a href="#">Sub Item 1</a></li>

    <li><a href="#">Sub Item 2</a></li>

    <li><a href="#">Sub Item 3</a></li>

    <li><a href="#">Sub Item 4</a></li>

    <li><a href="#">Sub Item 5</a></li>

    </ul>

    </li>

    <li class="topitem">Top Item 7

    <ul>

    <li><a href="#">Sub Item 1</a></li>

    <li><a href="#">Sub Item 2</a></li>

    <li><a href="#">Sub Item 3</a></li>

    <li><a href="#">Sub Item 4</a></li>

    <li><a href="#">Sub Item 5</a></li>

    </ul>

    </li>

    </ul>

    </body>

    </html>


    As I said before, the structure of the drop-down menu that I plan to build is composed of a set of nested lists, which also contain all of the pertinent links. Also, it's clear to see here that nested lists provide a solid, standard approach for constructing hierarchical menus like the one shown above.

    Okay, at this moment everything looks pretty good, since the markup of the menu is already set. So, what comes next? Well, actually the menu in its current incarnation does nothing useful. This means that it's necessary to write some CSS styles that prevent all of the menu's sub items from being displayed when the web page is loaded.

    Thus, in the following segment I'll be discussing in detail the definition of these CSS styles. To learn more on this topic, click on the link that appears below and keep reading.

    More HTML Articles
    More By Alejandro Gervasio


       · This final part of the series shows how to use nested HTML lists specifically for...
     

    HTML ARTICLES

    - Hello HTML 5, Goodbye Gears
    - Comparing Browser Response to Active Client ...
    - Testing Browser Response to Active Client Pa...
    - Active Client Pages: Completing the Code for...
    - ACP and Browsers: Setting up an Example
    - How Browsers Respond to Active Client Pages
    - Completing a Tree with Active Client Pages
    - HTML Form Verification and ACP
    - Building an ACP Tree
    - Completing an ACP 3D HTML Table Image Gallery
    - Building an ACP 3D HTML Table Image Gallery
    - A Multiple Page Image Gallery with Active Cl...
    - Building an Image Gallery with Active Client...
    - Concluding a Menu for All Browsers
    - A Vertical Menu for All Browsers







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek