Edward Osei-Nyarko
Edward Osei-Nyarko

Reputation: 11

Using CSS-Selectors in HTML

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

Answers (1)

Hunter Turner
Hunter Turner

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

Related Questions