给定以下代码:
div, span {
padding: 10px;
display: block;
}
.light-background {
background-color: #cacaca;
}
.dark-background {
background-color: #333;
}
.dark-background span {
color: white;
}
.light-background span {
color: black;
}
<div class="light-background">
<div class="dark-background">
<span>Here is some light text on a dark background.</span>
<div class="light-background">
<span>Here is some dark text on a light background.</span>
</div>
</div>
<span>Here is some dark text on a light background.</span>
</div>
最内层的跨度与 和 都匹配.dark-background span
,.light-background span
因此似乎只与 CSS 级联权重和最后一个规则定义的级联有关系,而规则中的两个选择器在HTML。
如果选择器匹配的元素比其他可能匹配的规则更接近,是否可以应用规则?