.thing {
color: red;
}
/* Additional rules here to honour the below request. */
<div>
<div class="thing">Should be red</div>
<div class="thing">Should be red</div>
<div class="thing">Should be red</div>
<div id="Excluder">
<div class="thing">Should not be red</div>
<div class="thing">Should not be red</div>
<div class="thing">Should not be red</div>
</div>
</div>
我想使所有类别为thing
的元素都具有红色,除了ID为Excluder
的元素中的项目之外
CSS / SCSS可以实现这种功能吗?
答案 0 :(得分:0)
您可以使用initial
属性将.thing
的子元素#Excluder
设置为其初始值。
.thing {
color: red;
}
#Excluder>.thing {
color: initial;
}
/* Additional rules here to honour the below request. */
<div>
<div class="thing">Should be red</div>
<div class="thing">Should be red</div>
<div class="thing">Should be red</div>
<div id="Excluder">
<div class="thing">Should not be red</div>
<div class="thing">Should not be red</div>
<div class="thing">Should not be red</div>
</div>
</div>
答案 1 :(得分:0)
Codepen演示:https://codepen.io/anon/pen/OeGvax
.thing {
color: red;
}
#Excluder {
.thing {
color: blue;
}
}
这会做你想要的。
如果您不想为#Excluder .thing
设置任何颜色,只需将color属性设置为unset或initial。
#Excluder {
.thing {
color: unset;
}
}
答案 2 :(得分:0)
使用&
变量重置.thing
元素内#Excluder
元素的颜色:
.thing{
color: red;
#Excluder > &{
color: initial;
}
}