Selector API - Descendant Selector

1 - About

Tree - Descendant in the selector API.

The descendant selector matches elements that are contained by (or “descended from”) another element.

A child is a direct descendant

3 - Syntax

The descendant relationship is shown with a space (or a * ?)

  • All descendant

/* All element descendant of E  */
E * 
/* All P descendant of E (ie all element P that are below E in the tree (child, little child, ....) */
E P 
/* or */
E * P  

  • First Descendant Level (child)

E >> P  

4 - Example

  • The HTML

     <p>This is the child element P of the root div and therefore a descendant of div. The style will be also applied on this text.</p>
          <p>This is a descendant of the root div. The style will be applied here.</p>

  • the CSS

div p { color:blue; }
div >> p { font-style:italic; } /* Work only on CSS4 */
body > div > p { font-size:2rem; }

  • The result

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap