Home arrow HTML arrow Page 3 - 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 - Polish the look of nested HTML lists with CSS styles
(Page 3 of 4 )

In the section that you just read, I discussed in detail how to build a few basic nested HTML lists. As I stated in that segment, itís necessary to improve the visual appearance of these web page elements, since in their current state they look rather primitive.

With that idea in mind, Iím going to define a brand new (X)HTML file. It will assign some CSS styles to a nested list that has one level of nesting. The file looks like this: 

<!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 multiple nested HTML lists (styled version)</title>

<style type="text/css">

body{

padding: 0;

margin: 0;

background: #fff;

}

/* 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{

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

color: #666;

margin: 0 0 5px 0;

}

</style>

</head>

<body>

<h1>Example on building multiple nested HTML lists</h1>

<ul>

<li>List Item 1

<ul>

<li>Sub Item 1</li>

<li>Sub Item 2</li>

<li>Sub Item 3</li>

<li>Sub Item 4</li>

<li>Sub Item 5</li>

</ul>

</li>

<li>List Item 2

<ul>

<li>Sub Item 1</li>

<li>Sub Item 2</li>

<li>Sub Item 3</li>

<li>Sub Item 4</li>

<li>Sub Item 5</li>

</ul>

</li>

<li>List Item 3

<ul>

<li>Sub Item 1</li>

<li>Sub Item 2</li>

<li>Sub Item 3</li>

<li>Sub Item 4</li>

<li>Sub Item 5</li>

</ul>

</li>

<li>List Item 4

<ul>

<li>Sub Item 1</li>

<li>Sub Item 2</li>

<li>Sub Item 3</li>

<li>Sub Item 4</li>

<li>Sub Item 5</li>

</ul>

</li>

<li>List Item 5

<ul>

<li>Sub Item 1</li>

<li>Sub Item 2</li>

<li>Sub Item 3</li>

<li>Sub Item 4</li>

<li>Sub Item 5</li>

</ul>

</li>

<li>List Item 6

<ul>

<li>Sub Item 1</li>

<li>Sub Item 2</li>

<li>Sub Item 3</li>

<li>Sub Item 4</li>

<li>Sub Item 5</li>

</ul>

</li>

<li>List Item 7

<ul>

<li>Sub Item 1</li>

<li>Sub Item 2</li>

<li>Sub Item 3</li>

<li>Sub Item 4</li>

<li>Sub Item 5</li>

</ul>

</li>

<li>List Item 8

<ul>

<li>Sub Item 1</li>

<li>Sub Item 2</li>

<li>Sub Item 3</li>

<li>Sub Item 4</li>

<li>Sub Item 5</li>

</ul>

</li>

<li>List Item 9

<ul>

<li>Sub Item 1</li>

<li>Sub Item 2</li>

<li>Sub Item 3</li>

<li>Sub Item 4</li>

<li>Sub Item 5</li>

</ul>

</li>

<li>List Item 10

<ul>

<li>Sub Item 1</li>

<li>Sub Item 2</li>

<li>Sub Item 3</li>

<li>Sub Item 4</li>

<li>Sub Item 5</li>

</ul>

</li>

</ul>

</body>

</html>

As you can see, the previous code sample is very simple to follow. All it does is assign some CSS styles to the <ul> and <li> elements of each nested list. Probably the most complex rule coded here is the one that styles items within the sub lists, represented by the following declaration:

li li{

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

color: #666;

margin: 0 0 5px 0;

}

However, the way the sub lists have been styled is pretty intuitive, since it uses an approach that doesnít differ too much from what youíve done hundreds of times before.

Of course, the previous example code would be rather incomplete if I didn't show you how this sample nested list looks after applying to it the pertinent CSS styles. So, hereís a screen shot that shows how the list is displayed on the browser:



You should now understand how to style HTML lists that have one level of nesting. Next, Iím going to discuss how to achieve this same styling process to build a hierarchical navigation bar.

This topic will be discussed in depth in the final section of this article. Thus, to learn more about it, 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-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials