<!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>
原文:https://www.cnblogs.com/eric-share/p/13759253.html