Cascade from "root" within nested style
Let's say that I have a navigation element. In Less, I might write it thus:
nav {
li {
background:red;
}
}
Now, let's say that when the BODY gets a class applied to it, the navigation element should change its background color. Unless I'm missing something, there's no way to write this the LESS way. Ideally, if LESS supported it I think it would look something like this:
nav {
li {
background:red;
/.newstate {
background:blue
}
}
Which would compile to:
nav li {background:red}
.newstate nav li {background:blue}
This can be done using the & operator:
nav {
li {
background:red;
.newstate & {
background:blue
}
}
}
compiles to:
nav li {
background: red;
}
.newstate nav li {
background: blue;
}
It would be nice if this usage was added to the documentation.
This should definitely go in the documentation. I've been waiting for a while now for a function like this just to find out that it was already built-in. Now I feel dumb.
It is documented and always has been, but the usage is not illustrated as inserting the ampersand & AFTER the nested selector, although I've seen a few other people talk about it.
moved to bug on website