如何将CSS规则应用于元素的所有后代 [英] How can I apply a css rule to all descendants of an elements
本文介绍了如何将CSS规则应用于元素的所有后代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果某个班级在另一个特定班级中,您怎么能重新定义该班级呢?
How can you redefine a class if its in another specific class?
div.cls {
color:blue;
}
div.tst > div.cls {
color:red;
}
<div class="cls">test</div> // text color = blue
<div class="tst">
<div class="cls">test</div> // text color = red
<div>
<div class="cls">test</div> // text color = blue
</div>
<div>
如何使最后一个也变红色?
How to make the last one also red?
推荐答案
使用 >
是 子选择器 [W3C] ,并且只会匹配元素的子代.
>
is the child selector [W3C] and will only match children of an element.
这篇关于如何将CSS规则应用于元素的所有后代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文