iphone6等移动端的css自适应
参考
http://jingyan.baidu.com/article/e73e26c0b3d36b24acb6a762.html
关键是
<metaname="viewport"content="width=320,maximum-scale=1.3,user-scalable=no">
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=320,maximum-scale=1.3,user-scalable=no"> </head> <style type="text/css"> html{font-size:100px;} body{font-size:0.14rem/*实际相当于14px*/} @media(min-device-width:375px)and(max-device-width:667px)and(-webkit-min-device-pixel-ratio:2){ html{font-size:117.1875px;} } /*iphone6plus*/ @media(min-device-width:414px)and(max-device-width:736px)and(-webkit-min-device-pixel-ratio:3){ html{font-size:129.375px;} } </style> <script type="text/javascript"> (function(doc,win){ var docEl=doc.documentElement, resizeEvt="onorientationchange" in window ? "orientationchange" : "resize", recalc=function(){ console.log(resizeEvt); var clientWidth=docEl.clientWidth; if(!clientWidth)return; docEl.style.fontSize=100*(clientWidth/320)+'px'; }; //AbortifbrowserdoesnotsupportaddEventListener if(!doc.addEventListener)return; win.addEventListener(resizeEvt,recalc,false); doc.addEventListener('DOMContentLoaded',recalc,false); })(document,window); </script> <body> hello </body> </html>
相关推荐
csstpeixun 2020-08-07
如狼 2020-08-15
anyushan 2020-06-30
zego实时音视频 2020-06-23
oKeYue 2020-06-14
xiaoxiaokeke 2020-05-19
AlisaClass 2020-05-16
Justdoit00 2020-04-26
rionchen 2020-04-09
86384798 2020-04-04
贤冰 2020-03-08
云端漂移 2020-03-05
数据与算法之美 2020-01-23
yuanran0 2019-12-25
CaiKanXP 2019-12-21