分享一个移动端rem布局的适配mixin

/*================================================================
以下为基于ip5 宽度320做的适配,标准html{font-size:10px},即1rem = 10px
=================================================================*/
@mixin queryWidth($min, $max) {
  @if $min == -1 {
    @media screen and (max-width: $max+px) {
      html {
        font-size: ( ($max+1) / 320 ) * 10px;
      }
    }
  } @else if $max == -1 {
    @media screen and (min-width: $min+px) {
      html {
        font-size: ( $min / 320 ) * 10px;
      }
    }
  } @else {
    @media screen and (min-width: $min+px) and (max-width: $max+px) {
      html {
        font-size: ( $min / 320 ) * 10px;
      }
    }
  }
}

@media only screen and (orientation: landscape) {
  html {
    font-size: 10px;
  }
}

@include queryWidth(-1, 319);    // for iphone 4
@include queryWidth(320, 359);   // for iphone 5
@include queryWidth(360, 374);
@include queryWidth(375, 383);   // for iphone 6
@include queryWidth(384, 399);
@include queryWidth(400, 413);
@include queryWidth(414, -1);    // for iphone 6 plus

 

  以上为基于320的设计稿,若要基于375,只需将mixin中320改为375即可。若要100px=1rem,只需将mixin中10改成100即可。当然,这只能实现大部分常规机型的适配,有些特殊机型还是需要自己再加上对应的适配。

  接下来罗列一下我用到过的适配,希望得到各位帮助逐步完善。

@media screen and (min-width: 320px) {} //for iphone 5
@media screen and (min-width: 375px) {} //for iphone 6
@media screen and (min-width: 414px) {} //for iphone 6 plus
@media screen and (min-aspect-ratio: 69/100) {} //for huawei荣耀6
@media screen and (min-aspect-ratio: 7/10) {} //for mx3
@media screen and (max-height: 480px) {} //for iphone 4
@media screen and (max-height: 420px) {} //for iphone 4 微信
@media only screen and (orientation: landscape) {} // for 横屏

 

个人博客:

http://mcchen.club

转载于:https://www.cnblogs.com/McChen/p/5017120.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值