guys, I don't know how to select a specific selector of class/id if I have many Paragraphs and I just want to select a specific one how I'm supposed to do that. For example, if I want to select the second Paragraph how I'm supposed to that? <p>World</p> Can I somehow just select that or I need to add another class.
Example:
HTML:
<div class="class">
<p>Hello</p>
<p>World</p>
</div>
How can I select the second paragraph <p>World</p>
Have a look at pseudo-class selector :nth-of-type()
In this case you just have to do .class > div:nth-of-type(2)
.class > p:nth-of-type(2) {
background-color: red
}
<div class="class">
<p>Hello</p>
<p>World</p>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With