1 回答

TA貢獻1828條經(jīng)驗 獲得超6個贊
就是類似于這樣就可以,
html { font-size: 62.5%; /* 10÷16=62.5% */ } @media only screen and (min-width: 481px){ html { font-size: 94%!important; /* 15.04÷16=94% */ } } @media only screen and (min-width: 561px){ html { font-size: 109%!important; /* 17.44÷16=109% */ } } @media only screen and (min-width: 641px){ html { font-size: 125%!important; /* 20÷16=125% */ } }
或者用rem布局也可以
說道標準,主要涉及到兩點
設計稿的尺寸
rem
到px
的轉(zhuǎn)換規(guī)則
舉個栗子,比如設計稿的尺寸的標準是720
,在720
的標準下,轉(zhuǎn)換規(guī)則為1rem
為100px
,這兩點標準定下來,就夠了。比如在設計稿中的某段文字的字體為20px
,根據(jù)轉(zhuǎn)換規(guī)則,在css中就是0.2rem
,那么在屏幕寬度為360px
的時候,我們希望字體為10px
,也就是同樣的0.2rem
為10px
,換算一下就是1rem
為50px
,這個50px
就是我們需要動態(tài)算的,所以下面計算用到的100
和720
就是這個標準,當clientWidth
為360
的時候,計算出來的fontSize
為 50
,也就是1rem
為50px
(function (doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
docEl.style.fontSize = 100 * (clientWidth / 720) + 'px';
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
添加回答
舉報