移動端rem布局

來源:互聯網
上載者:User

標籤:

手機頁面——解析度特別亂:1.定寬320px——優點:簡單,缺點:不能適應2.百分比——優點:能適應各種解析度,缺點:太麻煩3.rem——優點:方便、適應各種解析度(首先定義一個“根大小”html{font-size:20px;}) rem :看的是html的字型大小(先得定html的font-size)html{font-size:20px;}
切圖,基本的寬度用320 注意:只要使用了rem切圖那就千萬別用px,和em。       rem——不能出現除了rem以外任何單位root->em       root         html  <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" /> initial:[?‘n???l]device: [d?‘va?s]        viewport             視口         width             裝置的寬度 (device )         initial-scale     初始化縮放比例         user-scalable     使用者縮放 當螢幕發生變化的時候(變大或變小),以320的螢幕為基準進行計算,螢幕的縮放比例大小,然後當window.onload和onresize的時候,重新給document的font-size賦值,從而達到適應螢幕變化的效果 99%的公司:3套頁面、偷懶2套(PC、手機和pad)——效果特別差通過後台判斷進入哪套頁面——跟前台無關 寫法1:封閉空間的寫法(function(win,doc){
   win.onload=win.onresize=function(){
      doc.documentElement.style.fontSize = doc.documentElement.clientWidth*20/320+‘px‘;
   };
})(window,document); 寫法2:window.onload=function(){
   document.documentElement.style.fontSize = document.documentElement.clientWidth/320*20+‘px‘;
   window.onresize = function(){
      document.documentElement.style.fontSize = document.documentElement.clientWidth/320*20+‘px‘;
   };
};

移動端rem布局

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.