本文介绍了rem与em在CSS中有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在网站源代码中,我有时会看到开发人员使用 rem
单位。是否类似于 em
?
In website source, I have sometimes seen developers use the rem
unit. Is it similar to em
? I tried it to see what it actually does, but what is it relative to?
HTML
<div>Hello <p>World</p></div>
CSS
div {
font-size: 1.4rem;
}
div p {
font-size: 1.4rem;
}
推荐答案
EM
相对于其父级字体大小
EM
s are relative to their parent's font size
REM
base font-size
REM
s are relative to a base font-size
当中间容器更改字体大小时,这一点很重要。具有EM的子元素将受到影响,使用REM的子元素将不受影响。
This is important when intermediate containers change font sizes. Child elements with EMs will be affected, those using REMs will not.
这篇关于rem与em在CSS中有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!