HTML
  Home arrow HTML arrow Page 3 - 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 / 3
    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 - Using CSS styles to turn the menu into a functional user interface


    (Page 3 of 4 )

    In the section that you just read, I defined the bare bones structure of the drop-down menu, which as you'll recall, was comprised of some nested HTML lists. Assuming that you already understood how this particular task was accomplished, now it's time to add to the menu's structure the CSS styles that make it work in most modern browsers, except for Internet Explorer 6 and below.

    Essentially, the group of CSS styles that turn the nested lists of the menu into a functional user interface are as follows:

    /* reset body styles */

    body{

    padding: 0;

    margin: 0;

    background: #666;

    }

    /* style unordered list */

    ul{

    padding: 0;

    margin: 0;

    list-style: none;

    }

    /* style menu items */

    li.topitem{

    float: left;

    position: relative;

    width: 100px;

    padding: 5px;

    background: #eee;

    font: bold 11px Tahoma, Arial, Helvetica, sans-serif;

    color: #000;

    border: 1px solid #000;

    }

    /* position and hide drop-down menu */

    li.topitem ul{

    display: none;

    position: absolute;

    top: 22px;

    left: 0;

    width: 150px;

    background: #fff;

    padding: 0px;

    border-bottom: 1px solid #ccc;

    }

    li > ul{

    top: auto;

    left: auto;

    }

    /* display drop-down menu (add an 'over' class attribute to list items for IE */

    li:hover ul,li.over ul{

    display: block;

    }

    #navbar li li a {

    display: block;

    font: normal 11px Verdana, Arial, Helvetica, sans-serif;

    color: #000;

    padding: 5px;

    height: 15px;

    text-decoration: none;

    border-top: 1px solid #ccc;

    border-left: 1px solid #ccc;

    border-right: 1px solid #ccc;

    }

    #navbar li li a:hover {

    color: #000;

    background: #eee;

    }

    Despite its apparently complexity, the above CSS styles are quite simple to follow, actually. They first style the top items of the menu, then initially hide the corresponding sub items, and finally enhance the visual appearance of the menu's links.

    So far, nothing unexpected, right? As you saw before, it's relatively easy to construct a drop-down menu like the one above by combining the functionality given by a few HTML lists, along with some "hover" CSS pseudo classes as well.

    In addition, there's a worthwhile point to consider here: in its current incarnation, the menu will function with browsers that support this pseudo class with all the elements of a web page, like Firefox and Opera -- but Internet Explorer 6 and below will ignore this feature, and therefore the menu won't work.

    Thus, to solve this small -- yet annoying -- issue, it's necessary to code a simple JavaScript snippet that makes the menu work with Internet Explorer too. This tiny client-side application will be coded in the upcoming section.

    To learn how this JavaScript program will be incorporated into this drop-down menu, please visit the following segment.

    More HTML Articles
    More By Alejandro Gervasio


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

    HTML ARTICLES

    - 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
    - Downloading Long HTML Pages with ACP







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