移动端的rem设置

104 篇文章 0 订阅

首先,先说一个常识,浏览器的默认字体高都是16px

  • 使用方法
    注意,rem是只相对于根元素htm的font-size,即只需要设置根元素的font-size,其它元素使用rem单位设置成相应的百分比即可;
1 /*16px * 312.5% = 50px;*/
2 html{font-size: 312.5%;}
1 /*50px * 0.5 = 25px;*/
2 body{
3     font-size: 0.5rem;
4     font-size\0:25px;
5 }

一般情况下,是这样子使用的

1 html{font-size:62.5%;} 
2 body{font-size:12px;font-size:1.2rem ;} 
3 p{font-size:14px;font-size:1.4rem;}
  • 优点
    用一个东西肯定要知道它的好处啦,由于其他字体大小都是基于html的,所以在移动端做适配的时候,可以使用这样的方法
 1 @media only screen and (min-width: 320px){
 2   html {
 3     font-size: 62.5% !important;
 4   }
 5 }
 6 @media only screen and (min-width: 640px){
 7   html {
 8     font-size: 125% !important;
 9   }
10 }
11 @media only screen and (min-width: 750px){
12   html {
13     font-size: 150% !important;
14   }
15 }
16 @media only screen and (min-width: 1242px){
17   html {
18     font-size: 187.5% !important;
19   }
20 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值