Visit Mozilla.org

CSS:Descendant selectors

From MDC

« CSS « CSS Reference

[edit] Summary

The combinator (that's meant to represent a space) separates two selectors and matches the 2nd element if it is a descendant of the 1st. It is similar to the child selectors element, but doesn't require that the descendant be a direct child of the parent.

[edit] Syntax

selector1 selector2 { style properties }


[edit] Examples

span { background-color: white; }
div span {
  background-color: DodgerBlue;
}

...where...

<div>
  <span>Span 1.
    <span>Span 2.</span>
  </span>
</div>
<span>Span 3.</span>

... should look like ...

Span 1. Span 2.
Span 3.

[edit] Notes