最简单的方式实现rem布局
2024-10-07 00:54:31
加上如下js,px转换成rem需要手动,计算方式:量的大小除以100,就等于rem,例如:量的设计稿元素宽度是120,那么就写成{width: 1.2rem},这样写有什么问题,待研究,也欢迎补充
<!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>
<script>
function resetFontSize() {
var baseFontSize = 100
var designWidth = 750
var width = window.innerWidth
var currentFontSize = (width / designWidth) * baseFontSize
document.getElementsByTagName('html')[0].style.fontSize = currentFontSize + 'px'
}
window.onresize = function () {
resetFontSize()
};
resetFontSize()
</script>
<style>
*{
padding:0;
margin:0;
}
body{
overflow: auto;
font-size: .28rem;
}
.box{
width:7.5rem;
height: 1rem;
background: #000;
} </style>
</head>
<body>
<div class="box"></div>
<p>42341</p> </body>
</html>
最新文章
- 2.用vs2015创建Dotnet Core的mvc项目
- Metronic 与 VS2013/2015 合作开发
- golang level
- WCF配置详解
- hdu 1527(威佐夫博奕)
- 四核网络机顶盒芯片局势分析(开放市场):rk3128将会成为四核主流
- hdu_5683_zxa and xor(非正解的暴力)
- Android中购物车的全选、反选、问题和计算价格
- Swing-GridBagLayout用法-入门
- python判断素数的方法
- Android--UI之ImageView
- mysql高性能6章总结(下) mysql查询优化
- 前后台分离开发--文件上传与下载,cookie,session
- Check the NativeLink log file
- java几个easy出错的小程序
- 解决Shiro+SpringBoot自定义Filter不生效问题
- maven私服的搭建
- PHP FTP函数
- UML概述
- 一 web爬虫,requests请求