LESS nested rule for selecting all except a pseudo element

Viewed 8958

I'm writing a LESS nested rule that at the moment looks like this:

.content {
     margin-bottom: 30px;
     &:last-child {
        margin-bottom: 0;
     }
}

But I want to do it with a not selector and not have to define the margin twice. I don't want to have to reset in the last-child-selector.

What I want to do is something like this:

.content {
   &:not(:last-child) {
        margin-bottom: 30px;
   }
}

Resulting CSS:

.content:not(:last-child) {
    margin-bottom: 30px;
}

But my syntax seems wrong, cause it's not working, no elements get a bottom margin of 30px.

I haven't used the not-selector before, so I'm a little uncertain about the syntax. Is it possible to do and if yes, how?

How do I write a rule in LESS syntax that selects every child element of a particular div, except the last one?

4 Answers
Related