小码哥的IT人生

CSS all 属性 详解

css3基础 2022-07-14 15:42:58小码哥的IT人生shichen

CSS all 属性

定义和用法

all 属性将除 unicode-bidi 和 direction 之外的所有属性重置为其初始值或继承的值。

实例

将应用于元素或元素父元素的所有属性更改为其初始值:

div {
  background-color: yellow;
  color: red;
  all: initial;
}

 

完整实例【亲自试一试】:

<!DOCTYPE html>
<html>
<head>
<style>
html {
  font-size: small;
  color: blue;
}
#ex1 {
  background-color: yellow;
  color: red;
}
#ex2 {
  background-color: yellow;
  color: red;
  all: inherit;
}
#ex3 {
  background-color: yellow;
  color: red;
  all: initial;
}
#ex4 {
  background-color: yellow;
  color: red;
  all: unset;
}
</style>
</head>
<body>
<p>未设置 all 属性:</p>
<div id="ex1">Shanghai is one of the four direct-administered municipalities of the People's Republic of China. Welcome to Shanghai!</div>
<p>all: inherit:</p>
<div id="ex2">Shanghai is one of the four direct-administered municipalities of the People's Republic of China. Welcome to Shanghai!</div>
<p>all: initial:</p>
<div id="ex3">Shanghai is one of the four direct-administered municipalities of the People's Republic of China. Welcome to Shanghai!</div>
<p>all: unset:</p>
<div id="ex4">Shanghai is one of the four direct-administered municipalities of the People's Republic of China. Welcome to Shanghai!</div>
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

CSS 语法

all: initial|inherit|unset;

属性值

描述
initial 将此属性设置为其默认值。参阅 initial
inherit 从其父元素继承此属性。参阅 inherit
unset 如果可继承,则将应用于元素或元素父元素的所有属性更改为其父值,否则将其更改为初始值。

技术细节

默认值: none
继承:
动画制作: 不支持。请参阅:动画相关属性
版本: CSS3
JavaScript 语法: object.style.all="initial"

浏览器支持

表格中的数字注明了完全支持该属性的首个浏览器版本。

Chrome Edge Firefox Safari Opera
Chrome IE / Edge Firefox Safari Opera
37.0 79.0 27.0 9.1 24.0

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024