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

What is a CSS Descendant Selector?

By , About.com Guide

A CSS descendant selector applies to the elements that are inside another element. For example an unordered list has a <ul> tag with <li> tags as descendants. Or if you make your list items anchors:

<ul>
<li><a href="">...</a></li>
</ul>

Define descendant selectors by using two type selectors separated by spaces.

li a {
text-decoration : none ;
}

But remember that it doesn't matter how many tags are in between the two tags. If the second element is enclosed anywhere within the first element it will be selected.

If you want to select all anchors that are descended from ul elements, you would write:

ul a {
text-decoration : none ;
}

And the selectors that you're descending from don't have to be type descendants. For example, you could set up a descendant selector off of an ID:

#navigation ul {
background-color : #ccc ;
}
Explore Web Design / HTML
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, 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
  4. CSS
  5. CSS Selectors
  6. CSS Descendant Selectors - What is a CSS Descendant Selector>

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

All rights reserved.