这篇翻译不完整。请帮忙从英语翻译这篇文章

 

CSS 关键字 unset 的属性如果有继承父级样式,则将该属性重新设置为继承的值,如果没有继承父级样式,则将该属性重新设置为初始值。换句话说这个unset关键字会优先用inherit的样式,其次会应该用initial的样式。它允许应用任意的CSS样式,包括CSS速记 all 关键字。

Examples

Color

 

CSS

 

.foo {
  color: blue;
}
.bar {
  color: green;
}

p {
  color: red;
}
.bar p {
  color: unset;
}

 

HTML

 

<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>

结果

Border

HTML

div {
	border: 1px solid green;
}

p {
  border: 1px solid red;
}

.bar p {
	border-color: unset;
}

css

<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>

 

结果

格式

规范 版本 评论
CSS Cascading and Inheritance Level 4
unset
Candidate Recommendation 与Level 3无变化
CSS Cascading and Inheritance Level 3
unset
Candidate Recommendation 初始规范

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 41Edge Full support YesFirefox Full support 27IE No support NoOpera Full support YesSafari Full support 9.1WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 27Opera Android Full support YesSafari iOS Full support 9.3Samsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support

 

参见

  • 使用initial将属性设置为其初始值。
  • 使用revert将属性重置为user-agent样式表规定的值(或用户样式,如果存在)。
  • 使用inherit使元素的属性与其父元素相同。
  •  all属性允许您一次将所有属性重置为其初始,继承,恢复或未设置状态。

文档标签和贡献者

此页面的贡献者: luna666, FE_dev, willard, LiNengNeng
最后编辑者: luna666,