Doubt in selecting last child using pseudo class

If I give a space after li, like li :last-child, what does this mean, because I did not get the required o/p, and without the space (li:last-child), I got the intended o/p, Can anyone clarify what the gap(li :last-child) mean ?

Welcome back @vaishnavi_A.N

:last-child can be used without an element directly in front. It then means: “The last child whatever element it is.”

  • ul li:last-child means: "The last child of <ul> if it’s also an <li>" :arrow_right: matches
  • ul li :last-child means: “The last child of <li> whatever element it is” :arrow_right: doesn’t match, because <li> hasn’t got any children

Does that make it clear?


1 Like

Hello @mikoMK,
As usual you are awesome :metal: mikoMK.
I also feel that I learn more when you or justSomeOne answers my question.
Thank you so much again.

1 Like

oh li :last-child , it searches for children of li since after “li”, there is a white space, which is a descendent combinator?
Just a guess…

1 Like

Thank you for the kind words. :blush:
I’m glad we can help you on your developer journey.


1 Like