图集1/2

正文 2520字数 680,493阅读


<!DOCTYPE html> <html> <head> <title>手机布局样式文件</title> <!--手机网站--> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> <meta name="format-detection" content="telephone=no" /> <!--jquery库--> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.0/jquery.min.js"></script> <script> //- 设置html标签font-size 针对手机布局js (function (doc, win) { var _root = doc.documentElement, resizeEvent = 'orientationchange' in window ? 'orientationchange' : 'resize', resizeCallback = function () { var clientWidth = _root.clientWidth, fontSize = 20; if (!clientWidth) return; //if(clientWidth < 640) { fontSize = 20 * (clientWidth / 320); /*} else { fontSize = 20 * (640 / 320); }*/ _root.style.fontSize = fontSize + 'px'; }; if (!doc.addEventListener) return; win.addEventListener(resizeEvent, resizeCallback, false); doc.addEventListener('DOMContentLoaded', resizeCallback, false); })(document, window); </script> </head><body> <!--不建议以 像素px单位 calc js等布局--> <style> .main1 { font-size: 12px; color: #fff; width: 300px; height: 300px; margin:auto; background: blue; } </style> <div class="main1"> 以 rem 单位布局示例 </div> <!--以 rem 单位布局示例 如 <html style="font-size: 20px;"> --> <style> .main2{ font-size:12px;/*字体只能用px作单位*/ color:#fff; width:15rem; /*300px除以20px*/ height:15rem; /*300px除以20px*/ margin:auto; background:red; } </style> <div class="main2"> 以 rem 单位布局示例 </div> </body> </html>
Run code
Cut to clipboard


    参考 http://www.cocoachina.com/webapp/20150715/12585.html http://www.xiaoxiangzi.com/Programme/CSS/4298.html http://less.bootcss.com/functions/ https://segmentfault.com/q/1010000002944457
    Run code
    Cut to clipboard