移动端字体设置rem,怎么设置

我们的手机屏幕宽度有时候不一致,字体设置一致就会展示样式有出入,对字体有兼容有两种方式

一:少部分手机适配px

 html{font-size:10px} 

 @media screen and (min-width:321px) and (max-width:375px){html{font-size:11px}} 

 @media screen and (min-width:376px) and (max-width:414px){html{font-size:12px}}

  @media screen and (min-width:415px) and (max-width:639px){html{font-size:15px}} 

  @media screen and (min-width:640px) and (max-width:719px){html{font-size:20px}} 

  @media screen and (min-width:720px) and (max-width:749px){html{font-size:22.5px}} 

  @media screen and (min-width:750px) and (max-width:799px){html{font-size:23.5px}} 

   @media screen and (min-width:800px){html{font-size:25px}}

二、使用rem对各种手机做rem的适配

rem的大小是相对与页面的根元素的大小,rem能适配各种手机

在vue的main.js中引入  import  “@/utils/js/rem.js”

      (function(d,c){

            var e=d.documentElement,

            b="orientationchange" in window?"orientationchange":"resize",

            a=function(){

                var f=e.clientWidth;

                if(!f){return}

                // if(f>750){

                //     f=640

                // }

                // e.style.fontSize=100*(f/640)+"px"

               if(f>750){

                    e.style.fontSize='100px'

                }else{

                    e.style.fontSize=100*(f/750)+"px"

                }

             };

             if(!d.addEventListener){

                 return

                }

                c.addEventListener(b,a,false);

                d.addEventListener("DOMContentLoaded",a,false)

            })(document,window);//大概跟元素的字体大小为50px  1rem=100px

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值