You almost got it right, you’re just missing the reference to the div element. The following works
.recurse div:nth-child(2) {
border: 2px solid red;
padding: 20px;
}
I think the reason a reference to div is needed because without it the CSS is not specific enough since the recurse class could be applied to more than one element type. By including div you are saying which element type within that class you are tageting which raises the specificity. Also I think that the nth-child selector is always preceded by an element.
:nth-child refers to that elements position within its current structure.
The fact you said div:nth-child is immaterial as far as that element’s position calculation is concerned.
All it means is that the css will find the second child no matter what element it is. If the second child is a p tag then your rule fails to be applied because you have added div to the front.
The css will only apply to a second child but only if that second child happens to be a div when using your css The css doesn’t count divs only; it counts all the child elements no matter their variety.
You could say .test:nth-child(2) but that doesn’t mean look for the second of .test. It means look for the 2nd child and if it also happens to have a class of test then apply the css.