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 ), the 1em is not a fixed value in the entire web page.
  • rem: relative unit, we can understand that as root 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 and ie9 among others.

Damiao_Lee
10 声望1 粉丝

my name is damiao.