Discussion on: Share your CSS knowledge

fidelve profile image
Fidel Sanchez-Bueno

I didn't learn this recently but I tend to forget it from time to time.

The nth-child() selector every now and then throws me off.

I don't know why but I always interpret it like "select the nth child of this element", when in reality is "select this element if it is also the nth child of its parent", to put it in code, let's say we have this structure:

<div class="parent">
    <div class="child"></div>
    <div class="child"></div>
    <div class="child"></div>

If I want to select the first div with the class name "child", I always first write .parent:nth-child(1), then realize my mistake when the code is not working and rewrite it as .child:nth-child(1)

peoray profile image
Emmanuel Raymond

Wow...today I learned. Thank you ;)