如何重置或者去掉某个css属性值

876 阅读1分钟

css赋的值被优先级更高的css覆盖了,此时需要 'unset'属性

unset优先级

给某个关键字设置了unset,例如 color: unset; 它首选会选择继承父级的属性,然后才去选择继承本身属性值, 即: inherit > initial

例如:

本身属性值p和span设置了color值,如果设置了unset,就会去选择继承h_bg的color值。

HTML:

<header class="h_bg">
  <p class="reset">title title title</p>
  <span class='reset'>text text text</span>
</header>
CSS:

p{
   color:red;
}
span{
   color:blue;
}
.h_bg{
  color:#FFF;
  background:#DEDEDE;
  padding:20px; 
  text-align:center;
  width:200px;
  height:200px;
}
.reset{
  color:unset;   //去掉这个属性,文字会优先使用spanPcolor值
}