課程
/前端開發(fā)
/HTML/CSS
/移動(dòng)web開發(fā)適配秘籍Rem
可以不適用sass 進(jìn)行適配嗎?
2018-04-26
源自:移動(dòng)web開發(fā)適配秘籍Rem 3-3
正在回答
老師那樣的做法就是調(diào)用function簡(jiǎn)化了代碼量,這種方法就是每次頁面加載都要引入計(jì)算,麻煩些對(duì)吧
額,上面那是固定的了,你就直接這樣(不用scss、sass...):
let htmlWidth=document.documentElement.clientWidth || document.body.clientWidth;
? ? ? ? let htmlDom=document.getElementsByTagName('html')[0];
? ? ? ? htmlDom.style.fontSize=htmlWidth/37.5+'px';
? ? ? ? window.addEventListener('resize',()=>{
? ? ? ? ? ? let htmlWidth=document.documentElement.clientWidth || document.body.clientWidth;
? ? ? ? ? ? let htmlDom=document.getElementsByTagName('html')[0];
? ? ? ? ? ? htmlDom.style.fontSize=htmlWidth/37.5+'px';
? ? ? ? ? ? console.log(htmlDom.style.fontSize);
? ? ? ? });
這個(gè)就老師寫的,基于iphone6(這個(gè)比例是最好計(jì)算的),這個(gè)時(shí)候字體想設(shè)計(jì)成16px的話就寫成1.6rem;
慕粉13027520178
冷月詩魂 回復(fù) 慕粉13027520178
你試試直接設(shè)置html的font-size=10px;然后后面的單位進(jìn)行比例計(jì)算就行,比如字體原本是16px;換成rem就是1.6rem;
舉報(bào)
移動(dòng)web不求人,全面掌握移動(dòng)web開發(fā)rem適配方案。
1 回答安裝sass問題
1 回答sass文件編譯不成功是為什么
1 回答這個(gè)sass文件去哪里找
4 回答如何配置sass和webpack等插件
1 回答不熟悉sass,有沒有純js代碼實(shí)現(xiàn)的,網(wǎng)上版本太多比較亂
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-05-11
老師那樣的做法就是調(diào)用function簡(jiǎn)化了代碼量,這種方法就是每次頁面加載都要引入計(jì)算,麻煩些對(duì)吧
2018-05-02
額,上面那是固定的了,你就直接這樣(不用scss、sass...):
let htmlWidth=document.documentElement.clientWidth || document.body.clientWidth;
? ? ? ? let htmlDom=document.getElementsByTagName('html')[0];
? ? ? ? htmlDom.style.fontSize=htmlWidth/37.5+'px';
? ? ? ? window.addEventListener('resize',()=>{
? ? ? ? ? ? let htmlWidth=document.documentElement.clientWidth || document.body.clientWidth;
? ? ? ? ? ? let htmlDom=document.getElementsByTagName('html')[0];
? ? ? ? ? ? htmlDom.style.fontSize=htmlWidth/37.5+'px';
? ? ? ? ? ? console.log(htmlDom.style.fontSize);
? ? ? ? });
這個(gè)就老師寫的,基于iphone6(這個(gè)比例是最好計(jì)算的),這個(gè)時(shí)候字體想設(shè)計(jì)成16px的話就寫成1.6rem;
2018-05-02
你試試直接設(shè)置html的font-size=10px;然后后面的單位進(jìn)行比例計(jì)算就行,比如字體原本是16px;換成rem就是1.6rem;