可能重复: Sorting a set of CSS selectors on the basis of specificity 我需要一个JS库的顺序从最具体的选择文本CSS选择器的文本到少特定的选择文本,其中特异性根据W3C规定 如果没有任何库,我可以使用JS或jQuery简单地编写它吗? CSS选择器文本可能为div#body .text。
我在我的样式表两个相互竞争的规则: #parent > div {
color: blue;
}
#child {
color: red;
}
下面是相关的HTML: <div id="parent">
<div id="child">What color is this text?</div>
<div>This should just be blue</di