继承了哪些 CSS 属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5612302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which CSS properties are inherited?
提问by Bogdan Verbenets
I've noticed that some properties are inherited in CSS, and some are not. For example, the text-size property is inherited, but the padding and margin are not inherited by the child blocks. So how to figure out which properties are inherited, and which are not?
我注意到有些属性在 CSS 中是继承的,有些则不是。例如,text-size 属性是继承的,但是子块不继承 padding 和 margin。那么如何判断哪些属性是被继承的,哪些不是呢?
回答by Blender
Here is the list of all inheritable properies. I'm working with W3C's information, so I'd guess it shouldbe correct. But knowing web browsers (IE specifically), some of these might not be inheritable by all browsers:
这是所有可继承属性的列表。我正在处理W3C 的信息,所以我猜它应该是正确的。但是了解网络浏览器(特别是 IE),其中一些可能无法被所有浏览器继承:
azimuth
border-collapse
border-spacing
caption-side
color
cursor
direction
elevation
empty-cells
font-family
font-size
font-style
font-variant
font-weight
font
letter-spacing
line-height
list-style-image
list-style-position
list-style-type
list-style
orphans
pitch-range
pitch
quotes
richness
speak-header
speak-numeral
speak-punctuation
speak
speech-rate
stress
text-align
text-indent
text-transform
visibility
voice-family
volume
white-space
widows
word-spacing
azimuth
border-collapse
border-spacing
caption-side
color
cursor
direction
elevation
empty-cells
font-family
font-size
font-style
font-variant
font-weight
font
letter-spacing
line-height
list-style-image
list-style-position
list-style-type
list-style
orphans
pitch-range
pitch
quotes
richness
speak-header
speak-numeral
speak-punctuation
speak
speech-rate
stress
text-align
text-indent
text-transform
visibility
voice-family
volume
white-space
widows
word-spacing
回答by David Bonnet
Blender's and Shaz's lists both enumerate all the inherited CSS 2.1 properties, including those for aural media such as azimuth
. Here below is a list without the aural-oriented properties, now including CSS3 properties.
Blender 和 Shaz 的列表都列举了所有继承的 CSS 2.1 属性,包括那些用于听觉媒体的属性,例如azimuth
. 下面是一个没有面向听觉属性的列表,现在包括 CSS3 属性。
border-collapse
border-spacing
caption-side
color
cursor
direction
empty-cells
font-family
font-size
font-style
font-variant
font-weight
font-size-adjust
font-stretch
font
letter-spacing
line-height
list-style-image
list-style-position
list-style-type
list-style
orphans
quotes
tab-size
text-align
text-align-last
text-decoration-color
text-indent
text-justify
text-shadow
text-transform
visibility
white-space
widows
word-break
word-spacing
word-wrap
border-collapse
border-spacing
caption-side
color
cursor
direction
empty-cells
font-family
font-size
font-style
font-variant
font-weight
font-size-adjust
font-stretch
font
letter-spacing
line-height
list-style-image
list-style-position
list-style-type
list-style
orphans
quotes
tab-size
text-align
text-align-last
text-decoration-color
text-indent
text-justify
text-shadow
text-transform
visibility
white-space
widows
word-break
word-spacing
word-wrap
回答by Shaz
- azimuth
- border-collapse
- border-spacing
- caption-side
- color
- cursor
- direction
- elevation
- empty-cells
- font-family font-size
- font-style
- font-variant
- font-weight
- font
- letter-spacing
- line-height
- list-style-image
- list-style-position
- list-style-type
- list-style
- orphans
- pitch-range
- pitch quotes
- richness
- speak-header
- speak-numeral
- speak-punctuation
- speak
- speech-rate
- stress
- text-align
- text-indent
- text-transform
- visibility
- voice-family
- volume
- white-space
- widows
- word-spacing
- 方位角
- 边界坍塌
- 边框间距
- 字幕侧
- 颜色
- 光标
- 方向
- 海拔
- 空单元格
- 字体系列字体大小
- 字体样式
- 字体变体
- 字体粗细
- 字体
- 字母间距
- 行高
- 列表样式图像
- 列表样式位置
- 列表样式类型
- 列表样式
- 孤儿
- 音高范围
- 推介报价
- 丰富
- 说话头
- 说数字
- 说话标点符号
- 说话
- 语速
- 压力
- 文本对齐
- 文本缩进
- 文本转换
- 能见度
- 声音家庭
- 体积
- 空白
- 寡妇
- 字间距
回答by Panu Logic
The best reference-page to answer this and similar questions (say which CSS properties are NOT inherited) I've found is:
回答这个问题和类似问题的最佳参考页面(说明哪些 CSS 属性不是继承的)我发现是:
https://www.w3.org/TR/CSS21/propidx.html
https://www.w3.org/TR/CSS21/propidx.html
It has a column for "inherited" (or not).
它有一列用于“继承”(或不继承)。
The page says "Several Sections of this specification have been updated". But I can't find a more up-to-date version of this anywhere, listing all CSS properties in a single concise table. But this table I think is great, just what I was looking for. Answers also the question of what are the possible values for each CSS-property, and the initial (= default) value.
页面上写着“本规范的几个部分已经更新”。但是我在任何地方都找不到它的更新版本,在一个简明的表格中列出了所有 CSS 属性。但我认为这张桌子很棒,正是我想要的。还回答了每个 CSS 属性的可能值以及初始(= 默认)值的问题。
If you want to see all inherited or non-inherited properties grouped together you could copy the text from the web-page and insert it into Excel etc. then sort it based on the column "Inherited?". It works I tried it.
如果您想将所有继承或非继承的属性组合在一起,您可以从网页复制文本并将其插入 Excel 等,然后根据“继承?”列对其进行排序。它有效我试过了。
回答by Leon Hoffmann
Full list incl. CSS3:
完整列表包括 CSS3:
azimuth
:active
background
border-collapse
border-spacing
border-width
caption-side
color
cursor
direction
elevation
empty-cells
font
@font-face
font-family
font-size
font-size-adjust
font-stretch
font-style
font-variant
font-weight
font
:focus
:first-child
::first-letter
::first-line
:hover
:lang
letter-spacing
line-height
list-style-image
list-style-position
list-style-type
list-style
orphans
opacity
page
pitch-range
pitch
quotes
richness
speak-header
speak-numeral
speak-punctuation
speak
speech-rate
stress
text-align
text-indent
text-transform
text-size-adjust
visibility
:visited
voice-family
volume
white-space
widows
word-spacing
azimuth
:active
background
border-collapse
border-spacing
border-width
caption-side
color
cursor
direction
elevation
empty-cells
font
@font-face
font-family
font-size
font-size-adjust
font-stretch
font-style
font-variant
font-weight
font
:focus
:first-child
::first-letter
::first-line
:hover
:lang
letter-spacing
line-height
list-style-image
list-style-position
list-style-type
list-style
orphans
opacity
page
pitch-range
pitch
quotes
richness
speak-header
speak-numeral
speak-punctuation
speak
speech-rate
stress
text-align
text-indent
text-transform
text-size-adjust
visibility
:visited
voice-family
volume
white-space
widows
word-spacing