How does `:nth-last-child` work when CSS is cascading in nature?

126 views Asked by At

I've learnt CSS like below statement:

It only can go further or deeper in DOM.

And that's the reason we don't have a previous selector like we do for next selector ( selector + nextLM ) or we don't have a parent selector because we can't go backwards in DOM tree as CSS engine's point of view.

So there should be two different questions here. If we accept the above explanation, I can't understand how can :nth-last-child() work. It's basically going backwards in DOM tree as it starts at the end of an element.

And if we don't accept our introduction, then why don't we have a previous element selector?

Thanks in advance for your time.

0

There are 0 answers