rem布局

作者: 随风飞2019 | 来源:发表于2020-05-11 22:15 被阅读0次

直接修改根public目录下的index.html
在下方加入一段script代码即可实现

<script>
const setHtmlFontSize = () => {
let htmlDom = document.getElementsByTagName('html')[0];
let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth || window.innerWidth;
    if (htmlWidth >= 750) {
        htmlWidth = 750;}
    if (htmlWidth <= 320) {
        htmlWidth = 320;}
    htmlDom.style.fontSize = (htmlWidth / 7.5 ) +"px"};
    window.onresize = setHtmlFontSize;
    setHtmlFontSize();
</script>

或者去掉script,直接放到main.js里面,也可以。

相关文章

网友评论

      本文标题:rem布局

      本文链接:https://www.haomeiwen.com/subject/dqfmnhtx.html