美文网首页
移动端H5页面制作规范(2)

移动端H5页面制作规范(2)

作者: 醉于麦田 | 来源:发表于2019-08-03 10:36 被阅读0次

计量单位的使用

css的计量单位有三种选择:

px: 固定的相素值

em: 相对父级元素的font-size设置来作为当前元素1em所代表的像素值,如父节点的font-size:10px,当前节点的font-size:1.2em,则当前节点的font-size实为12px;

rem:相对根节点html的font-size设置来作为当前元素1rem所代表的像素值,与em的区别就是rem的基本度量单位与父节点无关,只与根节点font-size的设置有关,如设置html{font-size:10px;}后当前dom所有节点的1rem都表示10px;

移动端开发中我们使用rem作为基本计量单位,同时将根节点默认字号大小设为font-size:62.5%,因移动端浏览器默认字号大小为16px;16*62.5%刚好为10px; 具体设置方法及使用示例

html{font-size:62.5%;/*刚好为10px;*/}#example{font-size:1.2rem}/*设置#example的字体大小为12px;*/#example div{font-size:1.4rem; width:10rem;height:10rem}/*设置#example子节点div的字体大小为14px;宽度为100px;高度100px*/

安卓下<textarea>标签的内容字体大小不支持rem设置,如有需要使用响应式及px单位设置其字体大小,暂时还未找到具体原因

不同分辨率的终端

在对主流手机终端进行统计得出,大部分手机的device-width为320px、360px、375px、384px、400px、414px,另外安卓pad的device-width为600px\800px。 手机屏幕分辨率宽度则在320px-1080px间,有少部分手机已经达到1152px和1440px。PS:ipad访问移动端建议跳转去对应的PC页面。

viewport设置

在移动端开发中,我们使用如下viewport设置

<!--viewport的设置--><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">

注:device-width实际上并不等于设备宽度,而是css宽度,它是根据设备屏幕宽度和屏幕像素密度换算得出的用于网页显示的css宽度

移动端设计稿750px*1134px的制作规范

css部分

/*reset.less*//* CSS Document */html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;  font-size:62.5%;}ul,li,div,p,body,h1,h2,h3,h4,h5,h6,dl,dt,dd{margin:0;padding:0;}li{list-style:none;}a{text-decoration:none; color: #2a2a2a; }input{ -webkit-appearance:none;outline:none}

*{outline: none; webkit-focus-ring-color: rgba(0, 0, 0, 0);-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none;}.hide{display:none;}body, html {width: 100%; font-family: "Microsoft YaHei","Helvetica Neue",Arial, HelveticaNeue, Helvetica, "BBAlpha Sans", sans-serif;font-weight: normal;display: -webkit-box;-webkit-box-orient: vertical; -webkit-box-align: center;}/* *{-webkit-backface-visibility: hidden;-moz-backface-visibility: hidden;-ms-backface-visibility: hidden;backface-visibility: hidden;} 用于解决某些情况下出现闪屏的问题,若无则不加*/body{opacity: 1;-webkit-transition:opacity 500ms ease-in;transition:opacity 500ms ease-in; }p,a,li{font-size:1.2rem; color:#434343}html{ font-size: 312.5%; } 

@media screen and (max-width:359px) and (orientation:portrait) {    html { font-size: 266.67%; } 

}

@media screen and (min-width:360px) and (max-width:374px) and (orientation:portrait) {    html { font-size: 300%; } 

}

@media screen and (min-width:384px) and (max-width:399px) and (orientation:portrait) {    html { font-size: 320%; } 

}

@media screen and (min-width:400px) and (max-width:413px) and (orientation:portrait) {    html { font-size: 333.33%; } 

}

@media screen and (min-width:414px) and (max-width:431px) and (orientation:portrait){    html { font-size: 345%; }

}

@media screen and (min-width:432px) and (max-width:479px) and (orientation:portrait){    html { font-size:360%; }

}

@media screen and (min-width:480px)and (max-width:639px) and (orientation:portrait){   html{ font-size:400%;}

@media screen and (min-width:640px) and (orientation:portrait){   html{ font-size:533.33%;}

}

例如750px设计稿上320px*200px字体大小为32px的区域样式为:

html{ font-size: 312.5%; } 

.div{    width:3.2rem;    height:2rem;    font-size:0.32rem    }

js部分

主要处理短屏下缩放,以及初始化时固定页面大小,防止竖屏下弹出键盘或横屏时页面发生缩放的情况

 var initScreen=function(callback){//初始化html  font-size

        $("html").css("font-size",document.documentElement.clientHeight/document.documentElement.clientWidth<1.5 ? (document.documentElement.clientHeight/603*312.5+"%") : (document.documentElement.clientWidth/375*312.5+"%")); //单屏全屏布局时使用,短屏下自动缩放

        //$("html").css("font-size",document.documentElement.clientWidth/375*312.5+"%");//长页面时使用,不缩放

        if(callback)callback();

    }function _onorientationchange(e){    if(window.orientation==90||window.orientation==-90){

        $("#forhorview").css("display", "-webkit-box");  //显示竖屏浏览提示框

    }else{//竖屏下恢复默认显示效果

        var st=setTimeout(initScreen,300);

         $("#forhorview").css("display", "none");    

    }

    _resize(e);

}

$(function(){

    initScreen();    window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize",     function(e){_onorientationchange(e);}, false);

})

html示例

<!doctype html><html>

    <head>

        <title>标题</title>

        <meta name="keywords" content="关键字" />

        <meta name="description" content="描述" />

        <meta name="format-detection" content="telephone=no" />

        <meta name="format-detection" content="address=no" />

        <!--for baidu 识别移动端页面并禁止百度转码-->

        <meta name="applicable-device"content="mobile"> 

        <meta http-equiv="Cache-Control" content="no-transform" />

        <meta http-equiv="Cache-Control" content="no-siteapp" />

        <!--viewport 设置,如果页面实际情况不允许缩放请加上,user-scalable=no-->

        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">

        <meta name="apple-mobile-web-app-capable" content="yes" />

        <link rel="stylesheet" type="text/css" href="css/index.less" />

    </head>

    <body>

        <div id="forhorview">

            <p>推荐使用竖屏浏览哦~</p>

        </div>

        <script src="js/zepto.min.js"></script>

    </body></html>

移动端开发细节和优化

在移动端使用新的css3样式代替原来在PC上的开发习惯

新的布局实现方式:使用display:box、box-flex代替float\display:inline-block; 实现更强大、更完美的流体布局,尤其在宽度为100%的布局中,实现横向并排元素宽度的自动伸缩以及水平垂直居中平均分布、首尾分布排列等。

垂直居中的实现方式:使用display:-webkit-box;-webkit-box-align: center;实现垂直居中。

尽量使用border-radius,box-shadow,text-shadow等css3样式实现诸如圆角、渐变色、盒子投影、字体投影,减少使用图片。

对于单色的icon图标,我们将会整理出一套常用图标,并制作成字体,利用css3的@font-face使用自定义字体导入,这样的话,可以像修改字体一样随意地修改图标的颜色、大小、背景色、特殊效果(如投影)等,而不再需要每一种颜色就需要切一份图片。

利用-webkit-transform:rotate(90deg)来获取旋转了不同角度的icon,避免每个角度需要切一张图片

在动画中,利用css3动画属性如-webkit-transform:translate(10px,12px)来改变元素的偏移位置,减少使用left和top来做位移动画

相关文章

  • 用心打造企业营销产品

    H5游戏开发 H5是一系列制作网页互动效果的技术集合,即H5就是移动端的web页面。而H5游戏,你可以看作是移动端...

  • 微信H5游戏有哪些

    H5是一系列制作网页互动效果的技术集合,即H5就是移动端的web页面。而H5游戏,你可以看作是移动端的web游戏,...

  • 移动端H5页面制作规范(2)

    计量单位的使用 css的计量单位有三种选择: px: 固定的相素值 em: 相对父级元素的font-size设置来...

  • H5交互规范

    移动端的H5页面,实际上是基于移动端特性适配的网页,它没有规定的具体的交互规范,但会遵循一些移动端使用的基本特性。...

  • 移动端H5页面制作规范

    计量单位的使用 css的计量单位有三种选择: px: 固定的相素值em: 相对父级元素的font-size设置来作...

  • 移动端如何适配?

    1、使用Flexible实现手淘H5页面的终端适配2、再聊移动端页面的适配3、如何在Vue项目中使用vw实现移动端...

  • 移动端web页面适配

    移动端Web页面,即常说的H5页面、手机页面、webview页面等。 手机设备屏幕尺寸不一,在做移动端的Web页面...

  • 移动端页面制作

    1.既然是移动端, 就一定要按照移动端规范走, 直接使用 Chrome 浏览器进行移动端开发测试 2.推荐固定宽度...

  • 如何拯救你的H5?移动端常见问题集锦,小白免入

    H5页面在移动端无法满屏自适应窗口,怎么办? H5页面在移动端字体应该怎么设置? 1.iOS 系统默认中文字体是H...

  • 接单

    接各种页面制作,pc端,移动端,小程序页面等等!为了避免纷扰,只接纯页面制作,包切图,有需要私聊! 微信:cbcm...

网友评论

      本文标题:移动端H5页面制作规范(2)

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