Arahan @at-root dalam SASS
Arahan @at-root bertujuan
untuk mengeluarkan peraturan daripada pemilih induk
ke akar fail.
Mari kita lihat contoh berikut dengan pemilih pada tahap penyarangan pertama:
.parent {
background-color: #fdd;
@at-root .child {
border: 1px solid;
}
}
Hasil daripada kompilasi, kita mendapat kod berikut:
.parent {
background-color: #fdd;
}
.child {
border: 1px solid;
}
Sekarang mari kita lihat cara
arahan @at-root berfungsi dengan
berbilang pemilih:
.main-parent {
background-color: #fdd;
@at-root {
.first-child {
border: 1px solid;
}
.second-child {
font-weight: bold;
}
}
.step-child {
color: #232523;
}
}
Selepas kompilasi, kod kelihatan seperti ini:
.main-parent {
background-color: #fdd;
}
.first-child {
border: 1px solid;
}
.second-child {
font-weight: bold;
}
.main-parent .step-child {
color: #232523;
}
Terangkan, apakah hasil kompilasi kod berikut:
.primary-button {
background-color: #3272c7;
@at-root {
.block-button {
color: #ff0000;
}
.content-button {
color: #ccb42a;
}
}
.warning-button {
border: 2px solid #232523;
}
}