-1
enter code here

 <div class="test"> 
  <p>One</p>
  <p>Two</p>
  <p>Three</p>
 </div>

I tried to change the text color of second paragraph tag only to red using the test class

But I don't know how to do that without having an tr or td here

Parit Sawjani
  • 729
  • 8
  • 24

2 Answers2

0

You can use the nth-child() selector to achieve this:

Some more answers here if you want to understand it further nth child selector`

.test p:nth-child(2) {
  color: red;
}
<div class="test">
  <p>One</p>
  <p>Two</p>
  <p>Three</p>
</div>
Parit Sawjani
  • 729
  • 8
  • 24
-1

    div.test p:nth-child(2) {
      background-color: red;
    }
 <div class="test"> 
  <p>One</p>
   <p>Two</p>
   <p>Three</p>
  </div>
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 13 '22 at 14:50