手機頁面的前端開發


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-width: 640px){
 5     #example {
 6         font-size: 20px;
 7     }
 8 }
 9 @media (max-width: 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">

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM