rem单位例子

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <script>
        window.onload = function(){
            getRem(750,100)
        };
        window.onresize = function(){
            getRem(750,100)
        };
        function getRem(pwidth,prem){
            var html = document.getElementsByTagName("html")[0];
            var oWidth = document.body.clientWidth || document.documentElement.clientWidth;
            html.style.fontSize = oWidth/pwidth*prem + "px";
        }
    </script>
    <style>
        .wrap{position:relative;top:0;left:0;bottom:0;right:0;background:#fefefe;}
        .title{width:100%;height:0.98rem;line-height:0.98rem;color:#fff;background:#e02222;text-align: center;font-size:0.32rem;}
        .box{
            width: 100%;
            height: 0.50rem;
            background: #000;
            font-size: 0.24rem;
            color: #fff;
            line-height: 0.50rem;
            text-align: center;
        }
        .box1{
            width: 30%;
            height:5rem;
            background: blue;
            font-size: 0.24rem;
            color: #fff;
        }
    </style>
</head>
<body>
    <div class="wrap">
        <div class="title">首页</div>
    </div>
   <div class="box">
       王胜利
   </div>
   <div class="box1">
       王胜利
   </div>
</body>
</html>

 

posted @ 2018-12-29 10:34  南瓜壳  阅读(271)  评论(0编辑  收藏  举报