Class 基于类的条件SCS/SASS
我想根据祖先类更改颜色。 我希望在CSS中获得的内容:Class 基于类的条件SCS/SASS,class,sass,ancestor,Class,Sass,Ancestor,我想根据祖先类更改颜色。 我希望在CSS中获得的内容: section.container-story .story-head .content h2 { color:#FF0000; } section.container-story.category_1 .story-head .content h2 { color:#00FF00; } 我的SCSS代码 section.container-story{ $story-color: #FF0000; .
section.container-story .story-head .content h2 {
color:#FF0000;
}
section.container-story.category_1 .story-head .content h2 {
color:#00FF00;
}
我的SCSS代码
section.container-story{
$story-color: #FF0000;
.story-head{
.content{
h2{
color: $story-color;
.category_1 &{
color: #00FF00;
}
}
}
}
}
有没有办法做到这一点
这是我不工作的笔:
谢谢只需使用
&
字符即可
$story-color: #FF0000;
.story-head{
.content{
h2{
section.container-story &{
color: $story-color;
}
section.container-story.category_1 &{
color: #00FF00;
}
}
}
}
是的,但我需要重写整棵树?事实上,我正在寻找一个更好的方法,如果它存在的话,尽管这是一个快速解决问题的方法。但我仍在寻找另一种方法。好的,谢谢!但是我失去了我的部分。容器故事的祖先。故事头和下面的其他人…不,你没有失去祖先。它只是用另一种方式定义的。