【发布时间】:2019-11-19 15:18:33
【问题描述】:
我现在有代码:
<div class="parent">
<div class="second select">
<div class="third">
<button>OK</button>
</div>
</div>
</div>
和他的 SCSS 代码:
.parent{
.second{
.third{
button{
background: red;
}
}
}
}
是否可以在 SCSS 中为按钮添加选择类而不为其创建单独的类型:
.parent{
.second{
.third{
button{
background: red;
}
}
&.select{
.third{
button{
background: green;
}
}
}
}
}
例如,使用 mixins 来查找这个项目(也许有现成的解决方案)
.parent{
.second{
.third{
button{
background: red;
@include find('.select',2){ // 2 or '.second' => 2 it's position (second) or search class ".second"
background: green;
}
}
}
}
}
【问题讨论】: