未设置 | unset
unset
unset
CSS关键词当它从其父继承了继承值,而其初始值没有,则unset
重置属性。换句话说,它inherit
在第一种情况下就像initial
关键字,而在第二种情况下就像关键字一样。它可以应用于任何CSS属性,包括CSS简写all
。
示例
颜色
.foo {
color: blue;
}
.bar {
color: green;
}
p {
color: red;
}
.bar p {
color: unset;
}
<p>This text is red.</p>
<div class="foo">
<p>This text is also red.</p>
</div>
<div class="bar">
<p>This text is green (default inherited value).</p>
</div>
结果:
边界
div {
border: 1px solid green;
}
p {
border: 1px solid red;
}
.bar p {
border-color: unset;
}
<p>This text has a red border.</p>
<div>
<p>This text has a red border.</p>
</div>
<div class="bar">
<p>This text has has a black border (initial default, not inherited).</p>
</div>
结果:
规范
Specification | Status | Comment |
---|---|---|
CSS Cascading and Inheritance Level 4The definition of 'unset' in that specification. | Working Draft | No changes from Level 3. |
CSS Cascading and Inheritance Level 3The definition of 'unset' in that specification. | Candidate Recommendation | Initial definition. |
浏览器兼容性
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 41 | 27 (27) | Edge build 10565+ | 28 | 9.1 |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | No support | 27.0 (27) | No support | No support | 9.3 |