<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--
em 相对自己的字体大小,自己没有看继承的
rem 相对单位 root html根字体的相对单位
-->
<style>
* {
margin: 0;
padding: 0;
}
html {
font-size: 10px;
}
div {
width: 37.5rem;
height: 20rem;
background: red;
font-size: 2rem;
}
/*
设计师的尺寸 真实的尺寸clientWidth
---------- = -------------------
写代码定的跟字体大小 实际的跟字体大小
*/
</style>
<script>
function torem() {
document.documentElement.style.fontSize = 10 * document.documentElement.clientWidth / 375 + 'px';
}
window.onload = window.onresize = torem;
</script>
<!--
关于单位
1、小单位 直接给px
2、关于像素 逻辑像素和物理像素
-->
</head>
<body>
</body>
</html>
rem适配
最新推荐文章于 2024-07-22 08:55:10 发布