Universal Selector in CSS
The universal selector *
allows you to select all elements.
Example
Let's select all the elements and color them red:
* {
color: red;
}
Example
Let's select all the elements inside the div
tag and color them red:
div * {
color: red;
}
Example
Let's select all the elements directly inside the div
tag and color them red:
div > * {
color: red;
}
Example
Let's select all span
tags that are inside any tag that is inside a div
tag:
div * span {
color: red;
}
Practical tasks
Given code:
<main>
<p>---</p>
<p>---</p>
<div>
<p>+++</p>
<p>+++</p>
</div>
<section>
<p>+++</p>
<p>+++</p>
</section>
</main>
Write a selector that will select all paragraphs that are inside any parent inside the main
tag.