1 html{ 2 font-size:62.5%; /* 10÷16=62.5% */ 3 } 4 body{ 5 font-size:1.2rem ; /* 12÷10=1.2 */ 6 } 7 p{ 8 font-size:1.4rem; 9 }
这里我是经过设置以下的代码来控制不一样设备下的字体大小显示使其达到自适应html
1 html { 2 font-size: 62.5%; 3 } 4 @media only screen and (min-width: 320px){ 5 html { 6 font-size: 94%!important; 7 } 8 } 9 @media only screen and (min-width: 375px){ 10 html { 11 font-size: 109%!important; 12 } 13 } 14 @media only screen and (min-width: 414px){ 15 html { 16 font-size: 125%!important; 17 } 18 }
也能够使用js控制不一样的设备宽度在根元素上设置不一样的字体大小(1rem为1/10屏幕宽度):web
1 ; 2 (function(win) { 3 var doc = win.document; 4 var docEl = doc.documentElement; 5 var tid; 6 7 function refreshRem() { 8 var width = docEl.getBoundingClientRect().width; 9 if (width > 540) { // 最大宽度 10 width = 540; 11 } 12 var rem = width / 10; // 将屏幕宽度分红10份, 1份为1rem 13 docEl.style.fontSize = rem + 'px'; 14 } 15 16 win.addEventListener('resize', function() { 17 clearTimeout(tid); 18 tid = setTimeout(refreshRem, 300); 19 }, false); 20 win.addEventListener('pageshow', function(e) { 21 if (e.persisted) { 22 clearTimeout(tid); 23 tid = setTimeout(refreshRem, 300); 24 } 25 }, false); 26 27 refreshRem(); 28 29 })(window);
在使用一些框架的时候,能够加入如下代码,强制浏览器使用Webkit内核,国内不少的主流浏览器都是双核浏览器:浏览器
1 <meta name="renderer" content="webkit">
好好学习,每天向上,有错欢迎指正!框架