移動端開發rem單位

來源:互聯網
上載者:User

標籤:function   查詢   element   dom   移動   nts   var   html   log   

1、用js計算

  

<script>        (function (doc, win) {          var docEl = doc.documentElement,            resizeEvt = ‘orientationchange‘ in window ? ‘orientationchange‘ : ‘resize‘,            recalc = function () {              var clientWidth = docEl.clientWidth;              if (!clientWidth) return;              docEl.style.fontSize = 20 * (clientWidth / 320) + ‘px‘;            };          if (!doc.addEventListener) return;          win.addEventListener(resizeEvt, recalc, false);          doc.addEventListener(‘DOMContentLoaded‘, recalc, false);        })(document, window);</script>

 

2、媒體查詢 “@media”

@media only screen and (max-width: 320px){html{font-size: 9px;} }@media only screen and (min-width: 320px) and (max-width: 352px){html{font-size: 10px;} }@media only screen and (min-width: 352px) and (max-width: 384px){html{font-size: 11px;} }@media only screen and (min-width: 384px) and (max-width: 416px){html{font-size: 12px;} }@media only screen and (min-width: 416px) and (max-width: 448px){html{font-size: 13px;} }@media only screen and (min-width: 448px) and (max-width: 480px){html{font-size: 14px;} }@media only screen and (min-width: 480px) and (max-width: 512px){html{font-size: 15px;} }@media only screen and (min-width: 512px) and (max-width: 544px){html{font-size: 16px;} }@media only screen and (min-width: 544px) and (max-width: 576px){html{font-size: 17px;} }@media only screen and (min-width: 576px) and (max-width: 608px){html{font-size: 18px;} }@media only screen and (min-width: 608px) and (max-width: 640px){html{font-size: 19px;} }@media only screen and (min-width: 640px){html{font-size: 20px;} }

 

移動端開發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.