Descendant Selector
Descendant Selector
The descendant selector matches all elements that are descendants of a specified element.
The following example selects all <p> elements inside <div> elements:
div p {
background-color: yellow;
}
The child selector selects all elements that are the children of a specified element.
The following example selects all <p> elements that are children of a <div> element:
div > p {
background-color: yellow;
}
example –
<div>
<p>Paragraph 1 in the div.</p>
<p>Paragraph 2 in the div.</p>
<section>
<!-- not Child but Descendant -->
<p>Paragraph 3 in the div (inside a section element).</p>
</section>
<p>Paragraph 4 in the div.</p>
</div>
Pseudo-classes
Syntax –
selector:pseudo-class {
property: value;
}
Pseudo-Elements
A CSS pseudo-element is used to style specified parts of an element.
Syntax –
selector::pseudo-element {
property: value;
}
::first-line - pseudo-element is used to add a special style to the first line of a text.
::first-letter pseudo-element is used to add a special style to the first letter of a text.
::before pseudo-element can be used to insert some content before the content of an element.
::after pseudo-element can be used to insert some content after the content of an element.