em换算px,rem换算px

<body>
  <style type="text/css" rel="stylesheet">
    html,body{
      font-size: 16px;
    }

    p {
      -webkit-margin-before: 2em;
      -webkit-margin-after: 2em;
      -webkit-margin-start: 0px;
      -webkit-margin-end: 0px;
    }

    .select {
      width: 50px;
      height: 1em;
      background: firebrick;
     }

    #parent {
      font-size: 25px;
    }

    #child01 {
      width: 100px;
      height: 10em;
      background: darkgoldenrod;
    }

    #child02 {
      width: 100px;
      height: 10rem;
      background: darkmagenta;
    }
  </style>
  <div class="select"></div>

  <p id="tag" style="float: left;">this is p</p>
  <div id="parent" style="float: left;">
    <div id="child01" style="float: left;">
      <p>this is child01</p>
    </div>
    <div id="child02" style="float: left;">
      <p>this is child02</p>
    </div>
  </div>

  </body>
  <script>
    var tagEle = document.getElementById("tag");
    var tagStyle = getComputedStyle(tagEle);
    console.log(tagStyle["fontSize"]);
  </script>

  1.em的值不是固定大小;

  2.em,rem会继承父元素的字体大小;

  3.em在body中声明字体大小,rem在html中声明字体大小,

  4.在-webkit-浏览器中最小13px,小于13px没效果。

  任意浏览器的默认字体高都是16px。所有未经调整的浏览器都符合: 1em=16px。那么12px=0.75em,10px=0.625em。为了简化font-size的换算,需要在css中的body选择器中声明Font-size=62.5%,这就使em值变为 16px*62.5%=10px, 这样12px=1.2em, 10px=1em, 也就是说只需要将你的原来的px数值除以10,然后换上em作为单位就行了。

posted @ 2016-09-18 15:04  LTING  阅读(1582)  评论(0编辑  收藏  举报