unset 

unset 关键字我们可以理解为不设置,其实,它是关键字initial和inherit的组合。

当我们给一个css属性设置了unset的话:

1,如果该属性默认继承属性,该值等同于inherit

2,如果该属性是非继承属性,该值等同于initial

使用unset继承/取消样式:

<div class="father">
    <div class="children">子级元素一</div>
    <div class="children unset">子级元素二</div>
</div>

.father {
    color: red;
    border: 1px solid black;
}
 
.children {
    color: green;
    border: 1px solid blue;
}
 
.unset {
    color: unset;
    border: unset;
}

1,由于color是可继承样式,设置color:unset的元素,最终表现为父级的颜色red.

2,由于border是不可继承样式,设置了border:unset的元素,最终表现为border:initial,也就是默认border样式,无边框。

 a{
            width:200px;
            height:100px;
            display:block;
            color:darkgreen;
            background-color: #1AA094;
        }
        a:focus{
            background-color:rebeccapurple;
        }
        a.active:focus{
            background-color:unset;
        }
<a href="#" class="active">我真的很困!</a>

原文链接:

相关文章:

  • 2022-12-23
  • 2021-08-24
  • 2021-09-04
  • 2021-12-06
  • 2022-12-23
  • 2021-10-08
  • 2021-11-08
猜你喜欢
  • 2021-06-12
  • 2022-02-13
  • 2021-10-25
  • 2021-09-11
  • 2021-08-07
相关资源
相似解决方案