乐趣区

em\px\rem区别whats-the-difference-between-em-px-and-rem

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.
退出移动版