In CSS, commonly, four types of combinators used which are:
- Descendant Selector (Space)
- Child Selector (>)
- Adjacent Sibling Selector (+)
- 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.