一 、确定设计图尺寸 (750 640 等)
下图以750为例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>rem - 自适应布局</title>
<meta http-equiv=Content-Type content="text/javascript;charset="utf-8">
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
<script>
document.getElementsByTagName('html')[0].style.fontSize = (document.doucmentElement.clientWidth / 750) *100 + "px";
</script>
<style>
*{margin:0;pading:0;}.
.box{width:0.4rem;height:0.4rem;background:black;}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
盒子box 在750px的设计图中 宽高 为40px * 40px ; 在
document.getElementsByTagName('html')[0].style.fontSize= ((window.innerWidth|| document.documentElement.clientWidth|| document.body.clientWidth) / 750) * 100 + "px";