Home arrow HTML arrow Page 2 - Building a Drop-Down Menu with Nested HTML Lists
HTML

Building a Drop-Down Menu with Nested HTML Lists


Welcome to the third part of a three-part series that shows you how to design with nested HTML lists. Today we'll take what we've learned in the previous two parts to a logical conclusion: building a full-fledged drop-down menu. We will even make sure that this menu is compatible with older browsers, such as Internet Explorer 6.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 21
May 29, 2009
TABLE OF CONTENTS:
  1. · Building a Drop-Down Menu with Nested HTML Lists
  2. · Start building a drop-down menu: the structural markup
  3. · Using CSS styles to turn the menu into a functional user interface
  4. · Making the menu compatible with Internet Explorer 6 and below

print this article
SEARCH DEVARTICLES

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.


blog comments powered by Disqus
HTML ARTICLES

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials