Reputation: 11
How do you give a <p>
tag element inside a third <div>
tag element in an HTML source code a background color in using CSS Selectors?
Upvotes: 0
Views: 59
Reputation: 6894
You can use the :nth-child() selector for this.
.container div:nth-child(3) p {
color: red;
}
<div class="container">
<div>
<p>Hello</p>
</div>
<div>
<p>I'm</p>
</div>
<div>
<p>Bob</p>
</div>
</div>
Upvotes: 1