TOP CATEGORIES

×

What is the CSS descendant selector?

R

R. Wilson

In CSS, commonly, four types of combinators used which are:

  1. Descendant Selector (Space)
  2. Child Selector (>)
  3. Adjacent Sibling Selector (+)
  4. General Sibling Selector (~)

But here we are going to discuss only the “Descendant Selector (Space)” CSS Selector

Descendant Selector (Space)

The descendant selector is used to select all the child elements of the specified element.

Example of Descendant Selector

div p {

     background-color: #00758F;

     color: #808080;

  } 

If you write the HTML code like:

<div>

        <p>This is a 1st paragraph.</p> //here Descendant Selector code will work

</div>

<p>This is a 2nd paragraph.</p> //here Descendant Selector code will not work

then the Descendant Selector will apply only to the 1st paragraph but this code not apply to the 2nd paragraph.

0 votes

Your Answer

Email: advertise@gdatamart.com

Donate: To Support US

© 2024 GDATAMART.COM (All Rights Reserved)