rem
rem是一种单位,等同于html跟元素的字体大小,比如html设置字体为20px,那么1rem等于20px,2rem=40px
动态计算html的字体大小
- 拿到屏幕宽度
- 计算字体大小
- 设置根元素的字号
var windowWidth = document.documentElement.getBoundingClientRect().width;
console.log("屏幕宽度", windowWidth);
// 字体大小
var fontsize = windowWidth / 37.5
console.log("字体大小", fontsize);
document.documentElement.style.fontSize = fontsize + 'px';
比如设计稿宽750,那么出去37.5就等于20
后面使用rem进行适配就可以了