css属性继承性

css样式继承指的是,特定的css属性可以向下传递到后代元素。

可继承的css属性

有继承性的属性有以下几类:

  1. “font”字体系列属性

包括 font、font-family、font-weight、font-size、font-style、font-variant、font-stretch、font-size-adjust

  1. “text”文本系列属性

包括 text-indent、text-align、line-height、word-spacing、letter-spacing、text-transform、direction、color

  1. 元素可见性

visibility、opacity

  1. “display:table”表格布局属性

caption-side、border-collapse、border-spacing、empty-cells、table-layout

  1. “display:list-item”列表布局属性

list-style-type、list-style-image、list-style-position、list-style

  1. 生成内容属性

quotes

  1. 光标属性

cursor

  1. 页面样式属性

page、page-break-inside、windows、orphans

  1. 声音样式属性

speak、speak-punctuation、speak-numeral、speak-header、speech-rate、volume、voice-family、pitch、pitch-range、stress、richness、azimuth、elevation

继承属性的优先级

在计算继承属性时需要考虑以下特殊情况:

  1. a 标签的字体颜色(color)不能被继承

  2. h1-h6 标签字体的大小(font-size)不能被继承

  3. strong 标签的字体粗细(font-weight)不能被继承

  4. s, strike, del, u, ins 标签的文本装饰(text-decoration)不能被继承

因为这些属性是有浏览器默认样式的,也就是说继承属性的优先级不如浏览器默认样式(user agent stylesheet)优先级高