<!doctype html>
<html lang="en" >
<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>rem与less适配</title>
<link rel="stylesheet" href="./css/app.css">
</head>
<body>
<div id="box">
</div>
<script>
document.documentElement.style.fontSize = document.documentElement.clientWidth / 10 + ‘px‘
// 最终
window.onresize = function(){
// 设置新的 font-size
document.documentElement.style.fontSize = document.documentElement.clientWidth / 10 + ‘px‘
}
</script>
</body>
</html>
*{
margin:0;
padding:0;
}
@fontSize: 375 / 10rem;
#box{
width:335 / @fontSize;
height:144/ @fontSize;
margin:.50/ @fontSize auto;
background:#999;
}
原文:https://www.cnblogs.com/eric-share/p/13759312.html