1. js 적응을 직접 사용
1 2 3 4 5 6 7 8 9 10 11 12 | ( 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 / 750) + 'px';
};
if (!doc.addEventListener) return ;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
|
로그인 후 복사
예: 100px=1rem;10px=0.1rem;1px=0.01rem;
2. js+less를 사용하여
1 2 3 4 5 6 7 8 | ( function (win) {
function setUnitA() {
document.documentElement.style.fontSize = document.documentElement.clientWidth / 10 + "px" ;
}
var h = null;
window.addEventListener( "resize" , function () { clearTimeout(h); h = setTimeout(setUnitA, 300); }, false);
setUnitA();
})(window);
|
로그인 후 복사
less를 조정합니다. 파일 상단에 @unit: 750/10rem을 정의한 다음 CSS 전체 파일의 단위 @unit을 직접 사용하세요.
예: 100px=100/@unit;10px=10/@unit;1px=1/@unit;
3. 적응을 덜 사용합니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | html {
font-size: 20px;
}
@media only screen and (min-width: 401px) {
html {
font-size: 25px !important;
}
}
@media only screen and (min-width: 428px) {
html {
font-size: 26.75px !important;
}
}
@media only screen and (min-width: 481px) {
html {
font-size: 30px !important;
}
}
@media only screen and (min-width: 569px) {
html {
font-size: 35px !important;
}
}
@media only screen and (min-width: 641px) {
html {
font-size: 40px !important;
}
}
@unit: 40rem;
|
로그인 후 복사
예: 100px=100/@unit;10px=10/@unit;1px=1/@unit;