小编Rus*_*ell的帖子

CSS 特定优先级

我的 h1 都为红色背景色。对于第一个 h1,ID 具有最高优先级,对于第二个 h1,内联具有最高优先级。为什么?

#myid      { background-color: pink; }
.main h1   { background-color: red; }
div h1     { background-color: blue; }
h1         { background-color: green; }
Run Code Online (Sandbox Code Playgroud)
<!-- 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>
Run Code Online (Sandbox Code Playgroud)

html css css-selectors css-specificity

3
推荐指数
1
解决办法
67
查看次数

标签 统计

css ×1

css-selectors ×1

css-specificity ×1

html ×1