eki-al eki-al - 5 months ago 8
CSS Question

difference between ul:last-child and ul :last-child

I am creating a tree with angular inspire by

https://codepen.io/philippkuehn/pen/QbrOaN with a recursive tamplate

I would like the last elements of my tree print as a columns.

The last

<a>
element is accessible with
li a:last-child
. But i didn't find the way to access to only the last
li


For explain my question title, i tried to access with

ul li:last-child


By some kind of mistake i put a space and i saw i didn't get the same result. (i set a background-color for helping)

ul li :last-child


What is the difference ? and as optional question, what could be the best way to access the last
li
?

ps: i am using sass

Answer

ul li:last-child selects the last li element inside the ul.

ul li :last-child selects the last element (it doesn't matter if it's a div, or p or any other) inside the li.

You can just use the first one.