标签:utf-8 fonts scale doctype user mini doc set 1.0
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title></title>
<style>
*{padding: 0; margin: 0;}
.box{height: 200px; width: 16rem; background: red;}
</style>
<script>
(function(){
var html= document.documentElement;
var hWidth=html.getBoundingClientRect().width;
console.log(hWidth);
html.style.fontSize=hWidth/16 + "px";
})()
</script>
</head>
<body>
<div class="box"></div>
</body>
</html>
//比如在 iPhone5 1rem就是20px
标签:utf-8 fonts scale doctype user mini doc set 1.0
原文地址:https://www.cnblogs.com/xiepei/p/9919841.html