initial:initial 关键字用于设置 CSS 属性为它的默认值,可作用于任何 CSS 样式。(IE 不支持该关键字)

https://developer.mozilla.org/en-US/docs/Web/CSS/initial

inherit:继承父元素的定义,前提该属性可继承

https://developer.mozilla.org/en-US/docs/Web/CSS/inherit

unset: initialinherit 的组合。 https://developer.mozilla.org/en-US/docs/Web/CSS/unset

  1. 如果该属性是默认继承属性,该值等同于 inherit
  2. 如果该属性是非继承属性,该值等同于 initial

revert:将属性值还原

https://developer.mozilla.org/en-US/docs/Web/CSS/revert

  1. 如果是在网站自定义的样式中使用,如果有用户自定义样式,则还原到用户自定义样式的属性值,如果该值不存在这还原到浏览器默认样式的属性值中
  2. 如果在用户自定义样式中使用,直接还原到浏览器默认样式中的定义
  3. 如果是在浏览器默认样式中使用,则等效于 unset

和 uset 的区别:

1
2
3
4
5
6
7
8
9
10
11
<style>
h3 {
font-weight: normal;
color: blue;
}
</style>

<h3 style="font-weight: unset; color: unset;">This will still have font-weight: normal, but color: black</h3>
<p>Just some text</p>
<h3 style="font-weight: revert; color: revert;">This should have its original font-weight (bold) and color: black</h3>
<p>Just some text</p>

font-weight 的初始值是 normal,因此unset 会把值还原到 normal

而浏览器属性会给 h 标签加上 bold 的默认属性值,因此 revert 会还原为 bold

其中关于 revert 中提到的 User-agent origin User origin Author origin,可参考 https://developer.mozilla.org/zh-CN/docs/Glossary/Style_origin

简单总结

Author origin:网站自定义

User-agent origin: 浏览器默认样式

User origin:用户通过其他方式注入,例如 Stylus Stylish.