var cw = document.documentElement.clientWidth; if (cw > 1920) { cw = 1920; } document.getElementsByTagName("html")[0].style.fontSize = 20 * ( cw / 960) + 'px'
上面代碼針對的是設計稿為1920時的寫法
這種設置下,比如設計稿一個box寬為40px,則轉換之后則可以寫成
width:1rem;
一般情況下對於單屏頁面高的設置可以采用vh單位
比如設計稿的box高為100px,設計稿單屏頁面高度為960px,則可以設置高為 100/960*100 vh
當然如果不是單屏頁面,基本上才用高和寬都用rem,保證設計稿的等比例實現
