共计 624 个字符,预计需要花费 2 分钟才能阅读完成。
em、px 和 rem 区别?
- px:绝对单位,页面按精确像素展示。
- em:相对单位,基准点为父节点字体的大小,如果自身定义了 font-size 按自身来计算(浏览器默认字体是 16px),整个页面内 1em 不是一个固定的值。
- rem:相对单位,可理解为”root em”, 相对根节点 html 的字体大小来计算,CSS3 新加属性,chrome/firefox/IE9+ 支持
what’s the difference between em
, px
and rem
?
px
: absolute unit, the page is displayed in priecise pixels.em
: relative unit, the reference point is the size of the font of the parent node. if the font-size is defined by itself. it’s calculated by itself. (the browser default font is 16px), the1em
is not a fixed value in the entire web page.rem
: relative unit, we can understand that asroot em
, relative to the font-size of the html of root node to calculate. and it’s a new attribute in css3, and support chrome, firefox andie9
among others.
正文完