Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting specific element

Tags:

css

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>

like image 858
Hunali Avatar asked Jul 13 '26 19:07

Hunali


1 Answers

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>
like image 50
Baldráni Avatar answered Jul 15 '26 07:07

Baldráni