1 //得到手机屏幕的宽度
2 let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
3 if(htmlWidth>750){htmlWidth=750}
4 //得到html的Dom元素
5 let htmlDom = document.getElementsByTagName('html')[0];
6 //设置根元素字体大小
7 htmlDom.style.fontSize = htmlWidth/20 + 'px';
8 htmlDom.style.margin = '0 auto';
9 htmlDom.style.maxWidth = 750 + 'px';

比如说,手机宽度像素为360px的话,1rem就是18px;像素为320px的话,1rem就是16px.

 

相关文章:

  • 2021-12-06
  • 2021-12-27
  • 2022-02-13
  • 2021-11-18
猜你喜欢
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2021-11-18
  • 2022-12-23
  • 2021-06-03
相关资源
相似解决方案