rem ratio test
css3 stipulates that the size of 1rem is the value of the font-size of the root element html.
通过设置 根元素<html>的font-size的大小,来控制整个html文档内的字体大小、元素宽高、内外边距等,
根据移动设备的宽度大小来实现自适应,不同的设备都展示一致的页面效果。
Rem width ratio design draft width first:
1rem = 100px
100vw = 750px
and so
1rem = 100vw / 7.5 = 13.333333333vw
// Finally set the root element font-size to 13.333333vw
Import: The following code is introduced at the beginning of the page to dynamically calculate font-size
function rem(){
document.documentElement.style.fontSize=document.documentElement.clientWidth / 7.5 + 'px';
}
rem();
window.onresize = rem;这样当1rem = 13.333333vw时,获得一个宽高为60px的div的rem值,直接:
div {
width: .6rem;
height: .6rem;
}
Author: tanks open beta _1b7c
link: https: //www.jianshu.com/p/b23e42283560
Source: Jane books
are copyrighted by the author. For commercial reprints, please contact the author for authorization, and for non-commercial reprints, please indicate the source.