手机页面的前端开发

1.元素使用rem单位(相对于html的font-size,单位px)

 1 /* 自动调节页面适配 */
 2 $(function(){
 3     (function(){
 4         var oContainer = $('#container');//body下的640px的容器 margin: 0 auto
 5         var oHtml = $('html').eq(0);
 6         changeHtmlFontSize();
 7         function changeHtmlFontSize(){
 8             var oContainerWidth = oContainer.outerWidth();
 9             oHtml.css('font-size',oContainerWidth/40+'px');
10         }
11         $(window).resize(function(){
12             changeHtmlFontSize();
13         })
14     })()    
15 })    

2.元素使用em单位(相对于自身的font-size,单位px)

 1 #example {
 2     font-size: calc(100vw / 32);   //vw 即view-width的意思
 3 }
 4 @media (min- 640px){
 5     #example {
 6         font-size: 20px;
 7     }
 8 }
 9 @media (max- 320px){
10     #example {
11         font-size: 10px;
12     }
13 }

媒体查询样式的条件 可以使用 and 满足想要的范围

注意:手机页面都要加上这个

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=0">

原文地址:https://www.cnblogs.com/youaremylife/p/9284276.html