例子
/*使用多的方式对一个标签进行更改颜色*/
#only{
background-color: #FF0000;
}
.content em{
background-color: green;
}
.wrapper > .content > .box{
background-color: gray;
}
div.wrapper > [class="content"] > #only.box{
background-color: gold;
}
<div class="wrapper">
<div class="content">
<em class="box" id="only">1</em><!--对这里进行上色-->
</div>
</div>
不同横行的选择器修饰同一个标签,谁优先?
/* 100 +1 =101 101 > 20 所以p标签呈现红色 */
#idDiv p{
background-color: red;
}
/* 10 + 10=20 */
.classDiv .classP{
background-color: green;
}
<div class="classDiv" id="idDiv">
<p class="classP" id="idP">1</p>
</div>
由此可得同一横行的选择器权重相加谁大,谁来修饰标签。