Direktiva @at-root në SASS
Direktiva @at-root është projektuar
për nxjerrjen e rregullave nga selektori-prind
në rrënjë të skedarit.
Le të shqyrtojmë shembullin e mëposhtëm me selektorët e nivelit të parë të vendosjes:
.parent {
background-color: #fdd;
@at-root .child {
border: 1px solid;
}
}
Si rezultat i kompilimit, ne kemi marrë kodin e mëposhtëm:
.parent {
background-color: #fdd;
}
.child {
border: 1px solid;
}
Tani le të shohim punën e
directivës @at-root me
disa selektorë:
.main-parent {
background-color: #fdd;
@at-root {
.first-child {
border: 1px solid;
}
.second-child {
font-weight: bold;
}
}
.step-child {
color: #232523;
}
}
Pas kompilimit, kodi duket kështu:
.main-parent {
background-color: #fdd;
}
.first-child {
border: 1px solid;
}
.second-child {
font-weight: bold;
}
.main-parent .step-child {
color: #232523;
}
Tregoni, si do të jetë rezultati i kompilimit të kodit të mëposhtëm:
.primary-button {
background-color: #3272c7;
@at-root {
.block-button {
color: #ff0000;
}
.content-button {
color: #ccb42a;
}
}
.warning-button {
border: 2px solid #232523;
}
}