此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。
unset
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2016年3月.
CSS 关键字unset 可以分为两种情况,如果这个属性本来有从父级继承的值(这个属性默认可以继承,且父级有定义),则将该属性重新设置为继承的值,如果没有继承父级样式,则将该属性重新设置为初始值。换句话说,在第一种情况下(继承属性)它的行为类似于inherit ,在第二种情况下(非继承属性)类似于initial。它可以应用于任何 CSS 属性,包括 CSS 简写属性all 。
In this article
示例
>Color
HTML
html
<p>This text is red.</p><div> <p>This text is also red.</p></div><div> <p>This text is green (default inherited value).</p></div>CSS
css
.foo { color: blue;}.bar { color: green;}p { color: red;}.bar p { color: unset;}结果
Border
HTML
html
<p>This text has a red border.</p><div> <p>This text has a red border.</p></div><div> <p>This text has has a black border (initial default, not inherited).</p></div>CSS
css
div { border: 1px solid green;}p { border: 1px solid red;}.bar p { border-color: unset;}结果
规范
| Specification |
|---|
| CSS Cascading and Inheritance Level 4> # inherit-initial> |