移動端 html基值(轉載)

來源:互聯網
上載者:User

標籤:art   str   height   event   color   cli   元素   它的   比例   

(function () {          document.addEventListener(‘DOMContentLoaded‘, function () {              var html = document.documentElement;              var windowWidth = html.clientWidth;              html.style.fontSize = windowWidth / 6.4 + ‘px‘;              // 等價於html.style.fontSize = windowWidth / 640 * 100 + ‘px‘;          }, false);      })();

這個6.4就是根據設計稿的橫向寬度640來確定的,假如你的設計稿是750

那麼 html.style.fontSize = windowWidth / 7.5 + ‘px‘;

(1)至此,font-size的基礎值就確定好了,而且知道該font-size值是手機deviceWidth跟設計稿的比例值的100倍(重要)

(2)那麼頁面元素該如何設定寬高、邊距

  例如:一個設計稿寬高為140px的表徵圖,左邊距為50px,那麼它的css應該這樣寫

.icon {    width: 1.4rem; /* 像素換算rem:140px / 100 = 1.4rem */    height: 1.4rem;    margin: 0 0 0 .5rem;}

因為html的font-size是放大了100倍,所以計算rem時,要用設計稿的實際像素除以100,140px /100 =1.4rem; 最後實際的像素大小就會由deviceWidth跟設計稿的橫向寬的比例自動計算出來。

 源自:http://blog.csdn.net/huang100qi/article/details/49886713

移動端 html基值(轉載)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.