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

Flexible CSS Descendants

By Jennifer Kyrnin, About.com

When using CSS descendants, it's easy to get hung up on the placement of those descendants. But CSS is very flexible. For example, you might have a page design with the following tags as children of each other:

html
  body
    div
      p
        span

If you want to define a style rule on all span elements within divs, you can write:

div p span { ... }

But that would not collect any spans that are within <h1> or other tags. To do that, you need to write:

div span { ... }

This would collect all spans that are within div tags - no matter how many layers are between the div and the span.

More Web Design / HTML Quick Tips

Explore Web Design / HTML

More from About.com

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. CSS
  5. Advanced CSS
  6. Flexible CSS Decendants

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

All rights reserved.