继承了哪些 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 00:11:41  来源:igfitidea点击:

Which CSS properties are inherited?

cssinheritance

提问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),其中一些可能无法被所有浏览器继承:

  1. azimuth
  2. border-collapse
  3. border-spacing
  4. caption-side
  5. color
  6. cursor
  7. direction
  8. elevation
  9. empty-cells
  10. font-family
  11. font-size
  12. font-style
  13. font-variant
  14. font-weight
  15. font
  16. letter-spacing
  17. line-height
  18. list-style-image
  19. list-style-position
  20. list-style-type
  21. list-style
  22. orphans
  23. pitch-range
  24. pitch
  25. quotes
  26. richness
  27. speak-header
  28. speak-numeral
  29. speak-punctuation
  30. speak
  31. speech-rate
  32. stress
  33. text-align
  34. text-indent
  35. text-transform
  36. visibility
  37. voice-family
  38. volume
  39. white-space
  40. widows
  41. word-spacing
  1. azimuth
  2. border-collapse
  3. border-spacing
  4. caption-side
  5. color
  6. cursor
  7. direction
  8. elevation
  9. empty-cells
  10. font-family
  11. font-size
  12. font-style
  13. font-variant
  14. font-weight
  15. font
  16. letter-spacing
  17. line-height
  18. list-style-image
  19. list-style-position
  20. list-style-type
  21. list-style
  22. orphans
  23. pitch-range
  24. pitch
  25. quotes
  26. richness
  27. speak-header
  28. speak-numeral
  29. speak-punctuation
  30. speak
  31. speech-rate
  32. stress
  33. text-align
  34. text-indent
  35. text-transform
  36. visibility
  37. voice-family
  38. volume
  39. white-space
  40. widows
  41. 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 属性。

  1. border-collapse
  2. border-spacing
  3. caption-side
  4. color
  5. cursor
  6. direction
  7. empty-cells
  8. font-family
  9. font-size
  10. font-style
  11. font-variant
  12. font-weight
  13. font-size-adjust
  14. font-stretch
  15. font
  16. letter-spacing
  17. line-height
  18. list-style-image
  19. list-style-position
  20. list-style-type
  21. list-style
  22. orphans
  23. quotes
  24. tab-size
  25. text-align
  26. text-align-last
  27. text-decoration-color
  28. text-indent
  29. text-justify
  30. text-shadow
  31. text-transform
  32. visibility
  33. white-space
  34. widows
  35. word-break
  36. word-spacing
  37. word-wrap
  1. border-collapse
  2. border-spacing
  3. caption-side
  4. color
  5. cursor
  6. direction
  7. empty-cells
  8. font-family
  9. font-size
  10. font-style
  11. font-variant
  12. font-weight
  13. font-size-adjust
  14. font-stretch
  15. font
  16. letter-spacing
  17. line-height
  18. list-style-image
  19. list-style-position
  20. list-style-type
  21. list-style
  22. orphans
  23. quotes
  24. tab-size
  25. text-align
  26. text-align-last
  27. text-decoration-color
  28. text-indent
  29. text-justify
  30. text-shadow
  31. text-transform
  32. visibility
  33. white-space
  34. widows
  35. word-break
  36. word-spacing
  37. 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
  • 方位角
  • 边界坍塌
  • 边框间距
  • 字幕侧
  • 颜色
  • 光标
  • 方向
  • 海拔
  • 空单元格
  • 字体系列字体大小
  • 字体样式
  • 字体变体
  • 字体粗细
  • 字体
  • 字母间距
  • 行高
  • 列表样式图像
  • 列表样式位置
  • 列表样式类型
  • 列表样式
  • 孤儿
  • 音高范围
  • 推介报价
  • 丰富
  • 说话头
  • 说数字
  • 说话标点符号
  • 说话
  • 语速
  • 压力
  • 文本对齐
  • 文本缩进
  • 文本转换
  • 能见度
  • 声音家庭
  • 体积
  • 空白
  • 寡妇
  • 字间距

Source

来源

回答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:

  1. azimuth
  2. :active
  3. background
  4. border-collapse
  5. border-spacing
  6. border-width
  7. caption-side
  8. color
  9. cursor
  10. direction
  11. elevation
  12. empty-cells
  13. font
  14. @font-face
  15. font-family
  16. font-size
  17. font-size-adjust
  18. font-stretch
  19. font-style
  20. font-variant
  21. font-weight
  22. font
  23. :focus
  24. :first-child
  25. ::first-letter
  26. ::first-line
  27. :hover
  28. :lang
  29. letter-spacing
  30. line-height
  31. list-style-image
  32. list-style-position
  33. list-style-type
  34. list-style
  35. orphans
  36. opacity
  37. page
  38. pitch-range
  39. pitch
  40. quotes
  41. richness
  42. speak-header
  43. speak-numeral
  44. speak-punctuation
  45. speak
  46. speech-rate
  47. stress
  48. text-align
  49. text-indent
  50. text-transform
  51. text-size-adjust
  52. visibility
  53. :visited
  54. voice-family
  55. volume
  56. white-space
  57. widows
  58. word-spacing
  1. azimuth
  2. :active
  3. background
  4. border-collapse
  5. border-spacing
  6. border-width
  7. caption-side
  8. color
  9. cursor
  10. direction
  11. elevation
  12. empty-cells
  13. font
  14. @font-face
  15. font-family
  16. font-size
  17. font-size-adjust
  18. font-stretch
  19. font-style
  20. font-variant
  21. font-weight
  22. font
  23. :focus
  24. :first-child
  25. ::first-letter
  26. ::first-line
  27. :hover
  28. :lang
  29. letter-spacing
  30. line-height
  31. list-style-image
  32. list-style-position
  33. list-style-type
  34. list-style
  35. orphans
  36. opacity
  37. page
  38. pitch-range
  39. pitch
  40. quotes
  41. richness
  42. speak-header
  43. speak-numeral
  44. speak-punctuation
  45. speak
  46. speech-rate
  47. stress
  48. text-align
  49. text-indent
  50. text-transform
  51. text-size-adjust
  52. visibility
  53. :visited
  54. voice-family
  55. volume
  56. white-space
  57. widows
  58. word-spacing