1

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

albttx
  • 3,444
  • 4
  • 23
  • 42
  • Possible duplicate of http://stackoverflow.com/questions/1126338/what-does-a-space-mean-in-a-css-selector-i-e-what-is-the-difference-between-c – Harry Jun 17 '16 at 13:06

3 Answers3

2

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.

Stickers
  • 75,527
  • 23
  • 147
  • 186
  • I know understand the difference, but it's not working for selecting only the last li ... – albttx Jun 17 '16 at 13:36
  • It works, but in a nested ul you will need something like `ul ul li:last-child` etc. to avoid it also selecting the middle ones. Here is a quick demo for it - https://jsfiddle.net/wzxydv51/ hope that helps. – Stickers Jun 17 '16 at 13:55
1

ul li:last-child: The last li inside ul

ul li :last-child: The last of any type inside li. This the same as ul li *:last-child

Midas
  • 7,012
  • 5
  • 34
  • 52
0

As of my knowledge ul li:last-child will work for last child. not ul li :last-child, this represents, ul inside li, inside :last-child, but which element? Hence ul li:last-child should work properly.

Joel Gauvreau
  • 3,586
  • 4
  • 29
  • 32
Samir
  • 1,312
  • 1
  • 10
  • 16