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.
Next: Using CSS styles to turn the menu into a functional user interface >>
More HTML Articles
More By Alejandro Gervasio