前端 h5 开发,rem 的计算,可直接拷贝查看效果和复制
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<meta content="telephone=no" name="format-detection" />
<meta name="format-detection" content="email=no" />
<meta http-equiv="Cache-Control" content="no-cache" />
<title>响应式布局</title>
<style>
html {
font-size: 20px;
width: 100%;
height: 100%;
}
body {
margin: 0;
padding: 0;
}
header,
footer {
width: 100%;
background: #17a578;
color: #fff;
font-size: 1rem;
text-align: center;
line-height: 2rem;
}
.footer {
position: fixed;
bottom: 0;
}
.public {
width: 5rem;
height: 5rem;
font-size: 1.2rem;
display: inline-block;
text-align: center;
color: #fff;
line-height: 5rem;
margin-top: 1rem;
}
.left {
background: #f00;
}
.center {
background: #048f74;
}
.right {
background: #000;
}
</style>
</head>
<body>
<header>页面头部</header>
<div class="box">
<div class="public left">左</div>
<div class="public center">中</div>
<div class="public right">右</div>
<div class="public left">左</div>
<div class="public center">中</div>
<div class="public right">右</div>
</div>
<footer class="footer">页面底部</footer>
<script>
(function (doc, win) {
var docEl = doc.documentElement;
var resizeEvt = "orientationchange" in window ? "orientationchange" : "resize";
var recalc = function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
docEl.style.fontSize = 16 * (clientWidth / 375) + "px";
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener("DOMContentLoaded", recalc, false);
})(document, window);
</script>
</body>
</html>