首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

未设置 | unset

unsetCSS关键词当它从其父继承了继承值,而其初始值没有,则unset重置属性。换句话说,它inherit在第一种情况下就像initial关键字,而在第二种情况下就像关键字一样。它可以应用于任何CSS属性,包括CSS简写all

示例

颜色

代码语言:javascript
复制
.foo {
  color: blue;
}
.bar {
  color: green;
}

p {
  color: red;
}
.bar p {
  color: unset;
}
代码语言:javascript
复制
<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>

结果:

边界

代码语言:javascript
复制
div {
  border: 1px solid green;
}

p {
  border: 1px solid red;
}

.bar p {
  border-color: unset;
}
代码语言:javascript
复制
<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

扫码关注腾讯云开发者

领取腾讯云代金券