<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
/*@media only screen and (min-width: 1920px){
html {
font-size: 16px !important;
}
}
@media only screen and (min-width: 2560px){
html {
font-size: 21px !important;
}
}
@media only screen and (max-width: 1920px){
html {
font-size: 10px !important;
}
}*/
html,body{
width: 100%;
height: 100%;
margin: 0;
}
.box{
width: 31.25rem;
height: 31.25rem;
background: blue;
}
.box0{
width: 31.25rem;
height: calc(100% - 31.875rem);
background: red;
margin-top: 0.625rem;
}
</style>
</head>
<body>
<div class="box"></div>
<div class="box0"></div>
<script>
var width = document.documentElement.clientWidth
var css = `
html{
font-size: ${width/1920*16}px;
}
`
document.write(`<style>${css}</style>`)
</script>
</body>
</html>
rem根据不同屏幕分辨率自适页面布局
于 2022-03-01 15:54:44 首次发布