SASS-тағы @at-root директивасы
@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;
}
}