移动端布局rem解决方案

移动端布局rem解决方案

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <script>
        (function (doc, win) {
            var docEl = doc.documentElement,
                    resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
                    recalc = function () {
                        var clientWidth = docEl.clientWidth;
                        if (!clientWidth) return;
                        if (clientWidth >= 640) {
                            docEl.style.fontSize = '100px';
                        } else {
                            docEl.style.fontSize = 100 * (clientWidth / 640) + 'px';
                        }
                    };
            if (!doc.addEventListener) return;
            win.addEventListener(resizeEvt, recalc, false);
            doc.addEventListener('DOMContentLoaded', recalc, false);
        })(document, window);
    </script>
    <title>Title</title>
    <style media="screen">
      html{-webkit-overflow-scrolling:touch;overflow-scrolling:touch;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;-webkit-user-select:none;-ms-user-select:none}
      body,button,input,select,textarea{font-family:TrebuchetMS,Rotobo,"Microsoft YaHei",sans-serif}
      body,dd,dl,dt,form,h1,h2,h3,h4,h5,h6,html,li,ol,p,select,ul{margin:0;padding:0}
      .box{height: 1rem;border:0.1rem solid #ddd;box-sizing:border-box;width:100%;}
      .left{float: left;font-size: 0.3rem;}
      .right{float: right;font-size: 0.3rem;}
    </style>
</head>
<body>
<div class="box">
  <div class="left">
    左边
  </div>
  <div class="right">
    右边
  </div>
</div>
</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • AMD 和 CMD 的区别有哪些?AMD 是 RequireJS 在推广过程中对模块定义的规范化产出。CMD 是 ...
    竿牍阅读 715评论 0 1
  • H5页面窗口自动调整到设备宽度,并禁止用户缩放页面//一、HTML页面结构 // width 设置viewp...
    tiandashu阅读 16,761评论 0 9
  • meta基础知识 H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 忽略将页面中的数字识别为电话号码 忽略And...
    Mycro阅读 920评论 0 11
  • 寝室的玉姐姐今天早上去拍摄婚纱照,为她化妆,目送她走出寝室,美丽、圣洁,心里竟有种奇妙的感觉,暖暖的,又有一点点酸...
    快乐的雨baby阅读 377评论 0 1
  • 我们走在深夜的街头, 许多的灯都已熄灭, 道路宽阔而寂寞, 我们并肩而行, 彼此很近,又很远。 我们走在深夜的街头...
    三水林枫阅读 719评论 11 23