The &
always refers to the parent selector when nesting. Think of the &
as being removed and replaced with the parent selector.
If you leave a space after & symbol, this means you are now referring to its' descendants if you don't leave a space, this means you refer to your parent itself.
For example
.container {
&.red {
background-color: red;
}
}
In this case, this will apply red background to the .container
element, if it also has a red
class attached to it in your DOM.
Example 2
.container {
& .red {
background-color: red;
}
}
In this case, it will make the background to be red-colored to any child, which has a .red
class inside a .container
element.
More details and complex examples here