console
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
font-size: 16px;
}
div {
width: 5rem;
height: 2rem;
font-size: .3rem;
background-color: pink;
}
</style>
</head>
<body>
<div>我是自适应的文字</div>
<script>
var design = 640;
var base = 100;
function responsive() {
var width = window.innerWidth;
var size = width / design * base;
document.documentElement.style.fontSize = size + "px";
}
responsive();
window.addEventListener("resize", responsive);
</script>
</body>
</html>