【发布时间】:2017-06-12 12:23:22
【问题描述】:
使用em 将放大的字体大小直接应用于<p> 标记和嵌套的<span> 标记会产生不同的结果。
body {
font-size: 14px;
}
p {
font-size: 1.4em;
}
.enlarge {
font-size: 1.7em;
}
<p>Normal paragraph text</p>
<p class="enlarge">Enlarged text</p>
<p><span class="enlarge">This text comes out larger than the above.</span></p>
我期待 <p class="enlarge"> 和 <p><span class="enlarge"> 给我同样的结果。
这是一个工作示例:https://jsfiddle.net/huymo47b/
【问题讨论】:
-
它适用于
rem,但不适用于em,因为rem是相对于body而em继承基于父元素的大小 -
如果字体大小为 14px,p 为 1.4em,那么 p 将为 1.4 x 14px (~19.6px)。如果 p 为 19.6px,.enlarge 为 1.7em,则 .enlarge 将为 19.6 x 1.7 (~33.32px)