是否可以通过这种方式定义样式?此示例中的类子项是红色的,除非它包含在我希望它重置的父类中,以便它采用parent的style属性中定义的颜色.
.child {
color: red;
}
.parent > .child {
color: _clear_;
}
<div class="parent" style="color:blue;">
<div class="child">Some Text</div>
</div>
Run Code Online (Sandbox Code Playgroud)
kha*_*out 11
我想color: inherit;为.parent > .child是你在找什么:
.child {
color: red;
}
.parent > .child {
color: inherit;
}Run Code Online (Sandbox Code Playgroud)
<div class="parent" style="color:blue;">
<div class="child">This will be blue</div>
</div>
<br/>
<div class="child">This will still be red</div>Run Code Online (Sandbox Code Playgroud)
JSFiddle样本