移动端适配rem

<!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

 

 

移动端适配rem

上一篇:Android--------------BroadcastReceiver的学习


下一篇:安卓Android基础第三天——数据库,ListView