zoukankan      html  css  js  c++  java
  • 手机端布局

    http://caibaojian.com/mobile-responsive-example.html

    它是根据什么计算的,这就跟设计稿有关了,拿网易来说,它的设计稿应该是基于iphone4或者iphone5来的,所以它的设计稿竖直放时的横向分辨率为640px,为了计算方便,取一个100px的font-size为参照,那么body元素的宽度就可以设置为 6.4rem,于是html的font-size=deviceWidth / 6.4。这个deviceWidth就是viewport设置中的那个deviceWidth。根据这个计算规则,可得出本部分开始的四张截图中html的font-size大小如下:·

    //code from http://caibaojian.com/mobile-responsive-example.html
    deviceWidth = 320,font-size = 320 / 6.4 = 50px
    deviceWidth = 375,font-size = 375 / 6.4 = 58.59375px
    deviceWidth = 414,font-size = 414 / 6.4 = 64.6875px
    deviceWidth = 500,font-size = 500 / 6.4 = 78.125px
      • (1)先拿设计稿竖着的横向分辨率除以100得到body元素的宽度:
        //code from http://caibaojian.com/mobile-responsive-example.html
        如果设计稿基于iphone6,横向分辨率为750,body的width为750 / 100 = 7.5rem
        如果设计稿基于iphone4/5,横向分辨率为640,body的width为640 / 100 = 6.4rem
      • (2)布局时,设计图标注的尺寸除以100得到css中的尺寸
      • 播放器高度为210px,写样式的时候css应该这么写:height: 2.1rem。之所以取一个100作为参照,就是为了这里计算rem的方便!
        • (3)在dom ready以后,通过以下代码设置html的font-size:
          document.documentElement.style.fontSize = document.documentElement.clientWidth / 6.4 + 'px';
        • 6.4只是举个例子,如果是750的设计稿,应该除以7.5。
        • (4)font-size可能需要额外的媒介查询,并且font-size不能使用rem,如网易的设置:
          @media screen and (max-321px){
              .m-navlist{font-size:15px}
          }
          
          @media screen and (min-321px) and (max-400px){
              .m-navlist{font-size:16px}
          }
          
          @media screen and (min-400px){
              .m-navlist{font-size:18px}
          }

    最后还有2个情况要说明:

    第一,如果采用网易这种做法,视口要如下设置:·

    //code from http://caibaojian.com/mobile-responsive-example.html
    <meta name="viewport" content="initial-scale=1,maximum-scale=1, minimum-scale=1">
          第二,当deviceWidth大于设计稿的横向分辨率时,html的font-size始终等于横向分辨率/body元素宽:
          原文链接:

    之所以这么干,是因为当deviceWidth大于640时,则物理分辨率大于1280(这就看设备的devicePixelRatio这个值了),应该去访问pc网站了。事实就是这样,你从手机访问网易,看到的是触屏版的页面,如果从pad访问,看到的就是电脑版的页面。如果你也想这么干,只要把总结中第三步的代码稍微改一下就行了:·

    //code from http://caibaojian.com/mobile-responsive-example.html
    var deviceWidth = document.documentElement.clientWidth;
    if(deviceWidth > 640) deviceWidth = 640;
    document.documentElement.style.fontSize = deviceWidth / 6.4 + 'px';

    前端开发博客

  • 相关阅读:
    2017.3.13-afternoon
    2017.3.13-morning
    2017.3.10-afternoon
    2017.3.10-morning
    2017.3.9-afternoon
    2017.3.9-morning
    神经网络入门
    webpack 安装
    git 常用命令
    mysql 用户管理和权限设置
  • 原文地址:https://www.cnblogs.com/na-w/p/8832144.html
Copyright © 2011-2022 走看看