More Related Content
Similar to Inheritance css继承
Similar to Inheritance css继承 (20)
Inheritance css继承
- 8. 后代元素
一个后代元素
牵引出所有元素
但他处于文档树低一级
后代元素
Descendants
- 11. 兄弟元素(LI)
和他的兄弟姐妹们
同一个爸爸
有同一个爸爸(UL)
相对父元素
兄弟姐妹们
- 16. 通过选择器
通过选择器
来选择HTML页面中的
来选择HTML
HTML页面中的
元素
p { color: red; }
选择 选择器
- 25. 看下面的CSS代码
Em元素并没有
单独特定的去定义他
p { color: red; }
- 31. 否则,
我们需要去单独定义
所有的
所有的后代元素,look,
p { color: red; }
p em { color: red; }
- 32. 非常大
css文件将会变得非常大
非常大,
开发和维护将极为困难
同时 下载速度
下载速度也将受到很大影响
- 35. 如果所有CSS属性
都会被继承,
非常严重的问题!
那对开发者来说是非常严重的问题!!
- 37. What?
例如:
如果border属性
会被继承的话,
将会发生什么?
将会发生什么?
- 38. Okey,
border
我们来给P元素一个border
border属性
p { border: 1px solid red; }
- 44. 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
- 48. 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
- 50. 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
- 52. 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
- 59. 这里我 仅仅 仅仅只给 p元素定 义了
font-size属性,
而em并没有单独定义
p { font-size: 80%; }
- 65. 我们还是使用与之前
一样的
HTML代码:
<p>
Lorem <em>ipsum</em> dolor
sit amet consect etuer.
</p>
- 69. Px属性值(14px)会重写
Px属性值(14px)会
属性值(14px)
浏览器默认的font-size的值(约为16px)。
浏览器默认的font-size 的值(约为16px
font-size的值(约为16px)。
新的属性值会被继承。
- 70. 所以em元素继承了14px属性值.
元素 属性值 计算后的属性值
默认font size 约16px
<body> 未单独定义 约 16px
<p> 14px 14px
<em> 未单独定义 继承值 = 14px
- 74. 所以em元素会继承13.6px
这个计算出来的值
元素 属性值 计算后的属性值
默 认 的 font 约16px
size
<body> 未单独定义 约16px
<p> 85% 16px x 85% = 13.6px
<em> 未单独定义 继承属性值 = 13.6px
- 78. 所以em元素继承属性值为
所以em
em元素继承属性值为
13.6px .
元素 属性值 计算后的属性值
默认 font size 约 16px
<body> 未单独定义 约16px
<p> .85em 16px x .85em = 13.6px
<em> 未单独定义 继承属性值 = 13.6px
- 81. 所有的标签都定义了font-size
单位为百分比的
属性值.
body { font-size: 85%; }
h1 { font-size: 200%; }
h2 { font-size: 150%; }
- 83. font-size
font-size属性继承情况如下
元素 属性值 计算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
- 89. body {
color: #222;
font-family: arial,
helvetica, sans-serif;
font-size: 90%;
}
h1, h2, h3 { color: green; }
h4, h5, h6 { color: black; }
- 91. 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;
}
- 93. }
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%; }
- 94. We’re done!
We’
:
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/)
本译文仅供技术交流使用,转载请说明出处,禁止从事商业用途