From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/css/unset/index.html | 115 +++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 files/zh-cn/web/css/unset/index.html (limited to 'files/zh-cn/web/css/unset/index.html') diff --git a/files/zh-cn/web/css/unset/index.html b/files/zh-cn/web/css/unset/index.html new file mode 100644 index 0000000000..3b33d4cf63 --- /dev/null +++ b/files/zh-cn/web/css/unset/index.html @@ -0,0 +1,115 @@ +--- +title: unset +slug: Web/CSS/unset +tags: + - CSS + - 布局 + - 未设置 + - 样式 +translation_of: Web/CSS/unset +--- +
{{CSSRef}}
+ +

如果CSS关键字 unset 从其父级继承,则将该属性重新设置为继承的值,如果没有继承父级样式,则将该属性重新设置为初始值。换句话说,在第一种情况下(继承属性)它的行为类似于{{cssxref("inherit")}} ,在第二种情况下(非继承属性)类似于{{cssxref("initial")}}。它可以应用于任何CSS属性,包括CSS简写属性 {{cssxref("all")}} 。

+ +

示例

+ +

Color

+ +

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

CSS

+ +
.foo {
+  color: blue;
+}
+.bar {
+  color: green;
+}
+
+p {
+  color: red;
+}
+.bar p {
+  color: unset;
+}
+
+ +

结果

+ +

{{ EmbedLiveSample('Color') }}

+ +

Border

+ +

HTML

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

+ +
div {
+  border: 1px solid green;
+}
+
+p {
+  border: 1px solid red;
+}
+
+.bar p {
+  border-color: unset;
+}
+ +

结果

+ +

{{ EmbedLiveSample('Border', 'auto', 200) }}

+ +

规范

+ + + + + + + + + + + + + + + + + + + + + +
规范版本评论
{{ SpecName('CSS4 Cascade', '#inherit-initial', 'unset') }}{{ Spec2('CSS4 Cascade') }}与Level 3无变化
{{ SpecName('CSS3 Cascade', '#unset', 'unset') }}{{ Spec2('CSS3 Cascade') }}初始规范
+ +

浏览器兼容性

+ +

{{ Compat("css.types.global_keywords.unset")}}

+ +

参见

+ + -- cgit v1.2.3-54-g00ecf