Директива @at-root у SASS-у
Директива @at-root је намењена
за издвајање правила из родитељског селектора
у корен фајла.
Хајде да погледамо следећи пример са селекторима првог нивоа угњежђења:
.parent {
background-color: #fdd;
@at-root .child {
border: 1px solid;
}
}
Као резултат компајлирања добили смо следећи код:
.parent {
background-color: #fdd;
}
.child {
border: 1px solid;
}
А сада погледајмо рад
директиве @at-root са
више селектора:
.main-parent {
background-color: #fdd;
@at-root {
.first-child {
border: 1px solid;
}
.second-child {
font-weight: bold;
}
}
.step-child {
color: #232523;
}
}
Након компајлирања код изгледа овако:
.main-parent {
background-color: #fdd;
}
.first-child {
border: 1px solid;
}
.second-child {
font-weight: bold;
}
.main-parent .step-child {
color: #232523;
}
Реците, какав ће бити резултат компајлирања следећег кода:
.primary-button {
background-color: #3272c7;
@at-root {
.block-button {
color: #ff0000;
}
.content-button {
color: #ccb42a;
}
}
.warning-button {
border: 2px solid #232523;
}
}