Директива @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;
}
}