Edward Osei-Nyarko Edward Osei-Nyarko - 4 months ago 8
HTML Question

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?

Answer

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>