Home arrow HTML arrow Page 4 - Styling Elements of Nested HTML Lists
HTML

Styling Elements of Nested HTML Lists


Welcome to the second part of a three-part series on designing with nested HTML lists. This series shows you how to nest HTML lists by using a hands-on approach, and demonstrates how to use them for building standards-compliant drop-down menus.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
May 22, 2009
TABLE OF CONTENTS:
  1. · Styling Elements of Nested HTML Lists
  2. · Review: building basic nested HTML lists
  3. · Polish the look of nested HTML lists with CSS styles
  4. · Building a hierarchical navigational system

print this article
SEARCH DEVARTICLES

Styling Elements of Nested HTML Lists - Building a hierarchical navigational system
(Page 4 of 4 )

Undoubtedly, this introductory guide on nesting HTML lists wouldnít be complete if didn't show you how to use them for building a hierarchical navigation bar. Therefore, the last example that Iím going to code will be aimed at creating this links bar, by using some nested lists.

The sample code that renders this navigational bar on the browser is as follows:

<!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>Example on building a navigation bar with nested HTML lists</title>

<style type="text/css">

body{

padding: 0;

margin: 0;

background: #fff;

}

h1{

font: bold 14pt Arial, Helvetica, sans-serif;

color: #00f;

}

/* style lists */

ul{

list-style: outside;

margin: 0 15px 10px 0;

}

/* item lists */

li{

font: bold 10pt Arial, Helvetica, sans-serif;

color: #000;

}

/* sub items */

li li{

margin: 0 0 5px 0;

}

a:link,a:visited{

font: normal 10pt Arial, Helvetica, sans-serif;

color: #00f;

text-decoration: none;

}

a:hover{

text-decoration: underline;

}

</style>

</head>

<body>

<h1>Example on building a navigation bar with nested HTML lists</h1>

<ul>

<li>List 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>List 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>List 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>List 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>List 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>List 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>

</ul>

</body>

</html>

As shown above, a simple navigation mechanism has been built by using some nested HTML lists. Despite its simplicity, this example is actually pretty illustrative. It recreates a real world scenario that you can see on the web every day, where many sites utilize this structure as the building block for seating their links sections.

In addition to the previous code sample, below I included an extra image that depicts the visual aspect of the links bar just created:



And lastly, with this hands-on example Iím concluding this article about building HTML lists. As always, feel free to copy and edit all of the code samples included in this tutorial, so you can acquire a more solid grounding in working with these web page elements.

Final thoughts

In this second chapter of the series, I showed you a couple of interesting things regarding the use of nested HTML lists in concrete situations, such as enhancing their visual appearance and creating a hierarchical navigation system.

Naturally, these arenít the only situations in which nested list can be useful. They can be employed, for instance, for building standard drop-down menus. This will be the topic that I plan to cover in the last part of this series; you won't want to miss it!


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials