-
Book Overview & Buying
-
Table Of Contents
Less Web Development Essentials (Second Edition)
By :
The & symbol plays a special and important role in Less as it references the parent of the current selector. You can use it to reverse the order of nesting, and to extend or merge classes. You will see that the following example will tell you more than what can be expressed in a thousand words:
.class1
{
.class2{
property: 5;
}
}
.class1
{
.class2 & {
property: 5;
}
}This code will compile into the following code:
.class1 .class2 {
property: 5;
}
.class2 .class1 {
property: 5;
}You can see that .class2 becomes the parent of .class1 when you use the & symbol after it. The & symbol can also be used to reference nesting that is outside the mixin, as can be seen in the example about the conditional .ie8 class in the Passing rulesets to mixins section.
The & symbol can also be used to nest and append pseudo classes to a class. Later on, you will see that you can use it to append classes too. A simple example...
Change the font size
Change margin width
Change background colour