CSS 属性分为 默认继承 和 默认不继承,决定了没有为元素的属性指定值时该如何计算值
控制继承的属性值:
inherit
:使子元素属性和父元素相同,开启继承initial
: 将属性的初始(或默认)值应用于元素(不是浏览器样式表的值)unset
:- 对于 默认继承 属性,等同
inherit
- 对于 默认不继承 属性,等同
initial
- 一般和
all
属性一起用
- 对于 默认继承 属性,等同
revert
:使用浏览器默认值revert-layer
:将属性值还原为上一层 @layer 中设置的同属性值,没有则等同revert
NOTE
direction 和 unicode-bidi 属性是唯二不受 all 简写属性影响的属性
【译】理解CSS关键字:“Initial”,“Inherit”和“Unset” - 掘金 (juejin.cn)
CSS又出了个revert-layer全局关键字😂 « 张鑫旭-鑫空间-鑫生活 (zhangxinxu.com)
可继承的 CSS 属性
- 文本与字体相关
- color:文字颜色(如表单元素默认不继承,需手动设置)。
- font-family:字体类型。
- font-size:字体大小。
- font-style:斜体样式(如 italic)。
- font-weight:字体粗细(如 bold)。
- font-variant:小型大写字母(如 small-caps)。
- line-height:行高。
- text-align:对齐方式(如 left/center)。
- text-indent:首行缩进。
- text-transform:文本转换(如 uppercase)。
- letter-spacing:字符间距。
- word-spacing:单词间距。
- white-space:空白处理(如 nowrap)。
- direction:文本方向(如 rtl)。
- quotes:引号样式(如 “”)。
- 列表相关
- list-style-type:列表项标记类型(如 disc/decimal)。
- list-style-image:列表项图像标记(如 url (…))。
- list-style-position:标记位置(如 inside/outside)。
- 表格相关
- border-collapse:表格边框合并(如 collapse)。
- border-spacing:表格边框间距(如 2px)。
- 其他
- visibility:元素可见性(如 hidden)。
- cursor:鼠标指针样式(如 pointer)。