1. Home
  2. Computing & Technology
  3. Web Design / HTML

Nested Lists and CSS Descendant Selectors

Examples

Descendant CSS selectors are getting much more popular in CSS style sheets because they give you a lot more control over precisely which elements you want to style. Add to that that child selectors and sibling selectors weren't widely supported until recently, and that adds to their popularity. But descendant selectors often select more than what you intend - with strange results.

Did You Mean to Display it This Way?

If you look at the following list, with an embedded list, it looks like I've embedded one ordered list inside another. But as you'll see from the HTML, the inner list is a bulleted list.

  1. An ordered list
  2. With 3 elements
  3. And one nested list inside it:
    • An unordered list
    • With 2 bullet points

The HTML:

<ol>
<li>An ordered list</li>
<li>With 3 elements</li>
<li>And one nested list inside it:
  <ul>
  <li>An unordered list</li>
  <li>With 2 bullet points</li>
  </ul></li>
</ol>

The CSS:

ol li { list-style-type: decimal; }

Return to the CSS Selector Errors Article

How to Fix It

Use the same HTML, but change your CSS selector to a child selector.

  1. An ordered list
  2. With 3 elements
  3. And one nested list inside it:
    • An unordered list
    • With 2 bullet points

The CSS:

ol > li { list-style-type: decimal; }

Return to the CSS Selector Errors Article

Explore Web Design / HTML
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

©2009 About.com, a part of The New York Times Company.

All rights reserved.