一、vue中將px自動轉成rem:
https://segmentfault.com/a/1190000015238394
二、px轉rem的方式:
原文鏈接:http://caibaojian.com/rem-and-px.html
1rem等於多少px呢?·
1rem等於html根元素設定的font-size的px值,假如我們在css裏面設定下面的css。
//code from http://caibaojian.com/rem-and-px.html
html{font-size:14px}
那麼後面的CSS裏面的rem值則是以這個14來換算,例如設定一個div寬度爲3rem,高度爲2.5rem.則它換算成px爲width:42px.height:35px,同理,假如一個設計稿爲寬度42px,高度爲35px,則換成成rem,則是42/14=3rem,35/14=2.5rem。
如果css裏面沒有設定html的font-size,則默認瀏覽器以1rem=16px來換算。
三、項目中使用rem,每個js文件加入以下代碼
function resize(){
var w=document.body.clientWidth;
document.querySelector("html").style.fontSize=w*20/1920+'px';
};
document.body.onresize=resize;
resize();