5

I have the following markup:

<div class="heading-container">
        <p class="stroke">Who we</p>
        <h2 class="section-title extreme-bold">Contact us</h2>
        <p class="stroke"></p>
</div>

Now I can select the 1st .stroke using the following selector:

.heading-container .stroke:nth-child(1){
    max-width: 200px;
}

but the The following does't work for the 2nd stroke class:

.heading-container .stroke:nth-child(2){
    max-width: 200px;
}

but the following again works:

.heading-container .stroke:nth-child(3){
    max-width: 200px;
}

Now why does the value 3 work for the 2nd nth-child slection?

For the 2nd nth-child is't the followig suppose to be appropriate:

.heading-container .stroke:nth-child(2){
    max-width: 200px;
}
peterh
  • 11,875
  • 18
  • 85
  • 108
Tenali Raman
  • 380
  • 5
  • 16

1 Answers1

10

nth child, as explained here selects based on elements that are the nth child of their parents.

so 1 is working, because the first stroke is the first child. 3 works because the second stroke is the third child. 2 won't work, because there are no strokes that are 2nd children, just h2

Sze-Hung Daniel Tsui
  • 2,282
  • 13
  • 20