首页 > 其他 > 详细

rem 固定值适配

时间:2020-10-02 00:01:58      阅读:42      评论:0      收藏:0      [点我收藏+]
<!doctype html>
<html lang="en" style="font-size: 100px;">
<head>
<meta 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">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{
margin:0;
padding:0;
}
#box{
width:1.59rem;
height:.89rem;
margin-left:.21rem;
margin-top: 2rem;
background:#886;
}
</style>
</head>
<body>
<div id="box">

</div>
<script>

// 获取布局视口宽度
// var width = document.documentElement.clientWidth;
// var x = width * 100 / 375;
// // 设置新的 font-size
// document.documentElement.style.fontSize = x + ‘px‘
// 简化
// document.documentElement.style.fontSize = document.documentElement.clientWidth * 100 / 375;

// 最终
window.onresize = function(){
// 设置新的 font-size
document.documentElement.style.fontSize = document.documentElement.clientWidth * 100 / 375 + ‘px‘
}


</script>
</body>
</html>

rem 固定值适配

原文:https://www.cnblogs.com/eric-share/p/13759253.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!