Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nesting :after of :last-child with LESS

Tags:

css

less

Using LESS I need to remove an :after property within an element's :last-child.

li {
    &:after {
        content: '/';
    }
    &:last-child {
        &:after {
            content: '';
        }
    }
}

This is obviously not correct nesting - what am I missing?

like image 357
Staffan Estberg Avatar asked Aug 15 '12 12:08

Staffan Estberg


2 Answers

It looks correct to me, but if it's not working then try not nesting that second :after:

li {
    &:after {
        content: '/';
    }
    &:last-child:after {
        content: '';
    }
}

If you mean that the :after pseudo-element still displays for the last child, then you'll definitely want to change content: ''; to content: none; instead. An empty string will still cause an empty box to be generated, while none generates no box.

like image 160
BoltClock Avatar answered Sep 26 '22 01:09

BoltClock


You can use also:

li {
&:not(:last-child):after {
    content: " | ";

  }
}
like image 34
Carlos Avatar answered Sep 22 '22 01:09

Carlos