CSS中属性可以继承及不可继承详解

html-css027

CSS中属性可以继承及不可继承详解,第1张

一、不能继承的属性

① 盒子模型所有属性:margin、padding、border、width、height。

② 轮廓及背景属性:outline、background。

③ 定位、显示、浮动属性:display、position、top、left、right、bottom、max-*(如max-height等)、overflow、clear、float、content、z-index。

④ 其他:vertical-align、text-decoration、text-shadow、white-space。

注意:内联元素不能继承:text-indent和text-align,但是块级元素可以。

二、元素可继承属性

① 所有元素可继承:visibility、cursor。

② 列表元素可继承:list-style、list-style-type、list-style-position、list-style-image。

③ 字体属性:line-height、color、font、font-family、font-size、font-style、font-variant、font-weight、font-size-adjust。

④ 文本属性:text-transform、direction,除了(text-decoration、text-shadow 内联元素不能继承 ) 块级 可继承。

⑤ 表格布局属性:caption-side、border-collapse、border-spacing、empty-cells、table-layout。

⑥ 其它属性:letter-spacing、word-spacing。

如果还有您知道的,希望可以留言补充。

如果喜欢,不要吝啬你的爱心“❤”哦!

还是我来告诉你吧!以下的都是可以被继承的,除了这些之外,其他的都不可被继承:文本相关属性:font-family,font-size,font-style,font-variant,font-weight,font,letter-spacing,line-height,text-align,text-indent,text-transform,word-spacing列表相关属性:list-style-image,list-style-position,list-style-type,list-style还有一个属性比较重要,color属性。

只有块元素才可以默认“继承”其父元素的width.

浮动元素和定位元素也是不默认(不自动)“继承”其父元素宽度的。

当符合css默认“继承”的情况下(子元素必须是块级元素且无定位或浮动),是不需要写width属性,就可以默认“继承”的。