【发布时间】:2019-02-16 09:14:58
【问题描述】:
我得到了两个 h1 的红色背景色。对于第一个 h1,ID 具有最高优先级,对于第二个 h1,内联具有最高优先级。为什么?
#myid { background-color: pink; }
.main h1 { background-color: red; }
div h1 { background-color: blue; }
h1 { background-color: green; }
<!-- the background-color expected
to be pink for the following h1 -->
<div class="main" id="myid">
<h1>This is paragraph one!</h1>
</div>
<!-- the background-color expected
to be brown for the following h1 -->
<div style="background-color:brown;" class="main" >
<h1>This is paragraph two!</h1>
</div>
【问题讨论】:
标签: html css css-selectors css-specificity