This is a basic example but I would like to add a class to a parent in a nested child.
Desired CSS:
.addon .checkbox { background: blue; }
.addon.active .checkbox { background: red; }
Using SASS
.addon {
.checkbox {
background: blue;
.active & { background: red }
.addon.active & { background: red }
}
}
This gives me the following:
.addon .checkbox {
background: blue;
}
.active .addon .checkbox {
background: red;
}
.addon.active .addon .checkbox {
background: red;
}
As you can see I am not able to get the desired result using the & symbol. Can I do what I want using nesting or would I have to write it out using normal css ways.
Answered:
.addon {
.checkbox {
background: blue;
@at-root #{selector-replace(&, '.addon', '.addon.active')} {
background: red;
}
}
}