關於rem單位的使用

rem在移動端應用可參考淘寶的頁面http://m.taobao.com (html的font-size經過動態計算獲取)javascript

頁面基準320px(20px),html font-size值的計算:html

[javascript] 
    var ele=document.getElementsByTagName("html")[0],  
            size=document.body.clientWidth/640*20;  //以640爲基準,640屏幕下html的font-size爲20px,如在320屏下,1.2rem的字體大小爲12px。
        ele.style.fontSize=size+"px"

注:需設置meta縮放比1:1
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />java

具體使用rem的方法利弊等內容詳見網址https://isux.tencent.com/web-app-rem.htmlweb

相關文章
相關標籤/搜索