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