我有下面的scss代码,我想整理一下。
$colors-2: #222;
$colors-1: #ff0;
.footer__region {
text-align: center;
&--country {
color: $colors-2;
cursor: pointer;
display: inline-block;
.heading-3 {
border-bottom: 2px solid transparent;
.active & {
border-bottom-color: $colors-1;
color: $colors-1;
}
}
}
}我想我可以在里面嵌套.active并添加& after以输出以下内容
.footer__region--country.active .heading-3 {
border-bottom-color: #ff0;
color: #ff0;
}但看来我做不到。有人知道有什么Sass方法可以做到这一点吗?
注意:.footer__region--country将是附加.active的项目,.heading-3将是子项目。
发布于 2017-05-10 11:54:39
幸运的是,对于您的示例,您可以使用@at-root指令和.a.b{}选择与.b.a{}相同的事实。这样,您就不必重复任何类名。
$colors-2: #222;
$colors-1: #ff0;
.footer__region {
text-align: center;
&--country {
color: $colors-2;
cursor: pointer;
display: inline-block;
.heading-3 {
border-bottom: 2px solid transparent;
@at-root .active#{&} {
border-bottom-color: $colors-1;
color: $colors-1;
}
}
}
}输出:
.footer__region {
text-align: center;
}
.footer__region--country {
color: #222;
cursor: pointer;
display: inline-block;
}
.footer__region--country .heading-3 {
border-bottom: 2px solid transparent;
}
.active.footer__region--country .heading-3 {
border-bottom-color: #ff0;
color: #ff0;
}https://stackoverflow.com/questions/43891403
复制相似问题