Upgrade to Pro — share decks privately, control downloads, hide ads and more …

高级CSS—继承

Avatar for cssrain cssrain
September 02, 2014

 高级CSS—继承

高级CSS—继承

Avatar for cssrain

cssrain

September 02, 2014
Tweet

More Decks by cssrain

Other Decks in Technology

Transcript

  1. 偶也, 偶也, 偶也, 偶也, 我们从文档树 我们从文档树 我们从文档树 我们从文档树 ( (

    ( (DOM DOM DOM DOM tree tree tree tree) ) ) ) 开始 开始 开始 开始
  2. CSS CSS CSS CSS规则 规则 规则 规则由 由 由 由5

    5 5 5个要素 个要素 个要素 个要素构成 构成 构成 构成
  3. 通过 通过 通过 通过选择器 选择器 选择器 选择器 来选择 来选择 来选择

    来选择HTML HTML HTML HTML页面中的 页面中的 页面中的 页面中的 元素 元素 元素 元素 p { color: red; } 选择 选择 选择 选择 选择器 选择器 选择器 选择器
  4. Now Now Now Now… … … … 什么是 什么是 什么是

    什么是 继承 继承 继承 继承? ? ? ?
  5. ALL ALL ALL ALL? ? ? ? 所有的 所有的 所有的

    所有的css css css css 属性都会继承吗? 属性都会继承吗? 属性都会继承吗? 属性都会继承吗?
  6. 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
  7. 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
  8. 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
  9. 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
  10. font-size font-size font-size font-size? ? ? ? Font-size Font-size Font-size

    Font-size会被继承吗 会被继承吗 会被继承吗 会被继承吗
  11. Example Example Example Example 1: 1: 1: 1: Pixels Pixels

    Pixels Pixels(单位) (单位) (单位) (单位)
  12. Px Px Px Px属性值 属性值 属性值 属性值(14px) (14px) (14px) (14px)会

    会 会 会重写 重写 重写 重写 浏览器默认的 浏览器默认的 浏览器默认的 浏览器默认的font-size font-size font-size font-size的值(约为 的值(约为 的值(约为 的值(约为16px 16px 16px 16px)。 )。 )。 )。 新的属性值会被继承。 新的属性值会被继承。 新的属性值会被继承。 新的属性值会被继承。
  13. 元素 属性值 计算后的属性值 默认font size 约16px <body> 未单独定义 约 16px

    <p> 14px 14px <em> 未单独定义 继承值 = 14px 所以em元素继承了14px属性值.
  14. 浏览器默认的 浏览器默认的 浏览器默认的 浏览器默认的font-size font-size font-size font-size值为 值为 值为 值为16px

    16px 16px 16px, , , , 那么计算出值为 那么计算出值为 那么计算出值为 那么计算出值为16px x 85% =13.6px
  15. 元素 属性值 计算后的属性值 默 认 的 font size 约16px <body>

    未单独定义 约16px <p> 85% 16px x 85% = 13.6px <em> 未单独定义 继承属性值 = 13.6px 所以em元素会继承13.6px 这个计算出来的值
  16. 元素 属性值 计算后的属性值 默认 font size 约 16px <body> 未单独定义

    约16px <p> .85em 16px x .85em = 13.6px <em> 未单独定义 继承属性值 = 13.6px 所以 所以 所以 所以em em em em元素继承属性值为 元素继承属性值为 元素继承属性值为 元素继承属性值为 13.6px 13.6px 13.6px 13.6px .
  17. 元素 属性值 计算font-size 默认font size 约16px <body> 85% 16px x

    85% = 13.6px <h1> 200% 继承值为 13.6px x 200% = 27.2px <h2> 150% 继承值为 13.6px x 150% = 20.4px <p> 未单独定义 继承值为 = 13.6px <em> 未单独定义 继承值为 = 13.6px font-size font-size font-size font-size属性继承情况如下
  18. For example, 我们可以对body元素设置 color, font-size and font-family 属性 body {

    color: #222; font-family: arial, helvetica, sans-serif; font-size: 90%; }
  19. body { color: #222; font-family: arial, helvetica, sans-serif; font-size: 90%;

    } h1, h2, h3 { color: green; } h4, h5, h6 { color: black; }
  20. body { color: #222; font-family: arial, helvetica, sans-serif; font-size: 90%;

    } h1, h2, h3 { color: green; } h4, h5, h6 { color: black; } h1, h2, h3, h4, h5, h6 { font-family: georgia, times, serif; }
  21. } h1, h2, h3 { color: green; } h4, h5,

    h6 { color: black; } h1, h2, h3, h4, h5, h6 { font-family: georgia, times, serif; } h1 { font-size: 200%; } h2 { font-size: 150%; } h3 { font-size: 125%; } #footer { font-size: 90%; }
  22. We We We We’ ’ ’ ’re re re re

    done! done! done! done! Connect: : : : Name:Alex E-mail:paintyang@hotmail.com Site:http://ued.iciba.com/ QQ:303683080 声明: 本文翻译自http://www.slideshare.net/maxdesign/css-inheritance-a-simple-stepbystep-tutorial?from=ss_embed 作者:Russ Weakley(http://www.slideshare.net/maxdesign/) 本译文仅供技术交流使用,转载请说明出处,禁止从事商业用途