移动端页面开发资源总结

移动端页面开发资源总结及技巧

工作了有一段时间,基本上都在搞移动端的前端开发,工作的过程中遇到过很多问题,bug的解决方案,记录下来,以便后用!!!内容并不是很全,以后每遇到一个问题都会总结在这里,分享给大家!

一、meta标签相关知识

1、移动端页面设置视口宽度等于设备宽度,并禁止缩放。

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

2、移动端页面设置视口宽度等于定宽(如640px),并禁止缩放,常用于微信浏览器页面。

<meta name="viewport" content="width=640,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />

3、禁止将页面中的数字识别为电话号码

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

4、忽略Android平台中对邮箱地址的识别

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

5、当网站添加到主屏幕快速启动方式,可隐藏地址栏,仅针对ios的safari

<meta name="apple-mobile-web-app-capable" content="yes" />
<!-- ios7.0版本以后,safari上已看不到效果 -->

6、将网站添加到主屏幕快速启动方式,仅针对ios的safari顶端状态条的样式

<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<!-- 可选default、black、black-translucent -->

viewport莫板

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="utf-8">
 5 <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
 6 <meta content="yes" name="apple-mobile-web-app-capable">
 7 <meta content="black" name="apple-mobile-web-app-status-bar-style">
 8 <meta content="telephone=no" name="format-detection">
 9 <meta content="email=no" name="format-detection">
10 <title>title</title>
11 <link rel="stylesheet" href="index.css">
12 </head>
13 
14 <body>
15     content...
16 </body>
17 
18 </html>

二、CSS样式技巧

1、禁止ios和android用户选中文字

.css{-webkit-user-select:none}

2、禁止ios长按时触发系统的菜单,禁止ios&android长按时下载图片

.css{-webkit-touch-callout: none}

3、webkit去除表单元素的默认样式

.css{-webkit-appearance:none;}

4、修改webkit表单输入框placeholder的样式

input::-webkit-input-placeholder{color:#AAAAAA;}
input:focus::-webkit-input-placeholder{color:#EEEEEE;}

5、去除android a/button/input标签被点击时产生的边框 & 去除ios a标签被点击时产生的半透明灰色背景

a,button,input{-webkit-tap-highlight-color:rgba(255,0,0,0);}

6、ios使用-webkit-text-size-adjust禁止调整字体大小

body{-webkit-text-size-adjust: 100%!important;}

7、android 上去掉语音输入按钮

input::-webkit-input-speech-button {display: none}

8、移动端定义字体,移动端没有微软雅黑字体

/* 移动端定义字体的代码 */
body{font-family:Helvetica;}

9、禁用Webkit内核浏览器的文字大小调整功能。

-webkit-text-size-adjust: none;

10、去掉 input[type=search] 搜索框默认的叉号

1 input[type="search"]{
2     -webkit-appearance:none;
3 }
4 input::-webkit-search-cancel-button {
5     display: none;
6 }

三、其他技巧

1、手机拍照和上传图片

1 <!-- 选择照片 -->
2 <input type=file accept="image/*">
3 <!-- 选择视频 -->
4 <input type=file accept="video/*">

2、取消input在ios下,输入的时候英文首字母的默认大写

<input autocapitalize="off" autocorrect="off" />

3、打电话和发短信

1 <a href="tel:0755-10086">打电话给:0755-10086</a>
2 <a href="sms:10086">发短信给: 10086</a>

四、CSS reset

 1 /* hcysun  */
 2 @charset "utf-8";
 3 /* reset */
 4 html{
 5     -webkit-text-size-adjust:none;
 6     -webkit-user-select:none;
 7     -webkit-touch-callout: none
 8     font-family: Helvetica;
 9 }
10 body{font-size:12px;}
11 body,h1,h2,h3,h4,h5,h6,p,dl,dd,ul,ol,pre,form,input,textarea,th,td,select{margin:0; padding:0; font-weight: normal;text-indent: 0;}
12 a,button,input,textarea,select{ background: none; -webkit-tap-highlight-color:rgba(255,0,0,0); outline:none; -webkit-appearance:none;}
13 em{font-style:normal}
14 li{list-style:none}
15 a{text-decoration:none;}
16 img{border:none; vertical-align:top;}
17 table{border-collapse:collapse;}
18 textarea{ resize:none; overflow:auto;}
19 /* end reset */

五、常用公用CSS style

 1 /* public */
 2 
 3 /* 清除浮动 */
 4 .clear { zoom:1; }
 5 .clear:after { content:''; display:block; clear:both; }
 6 
 7 /* 定义盒模型为怪异和模型(宽高不受边框影响) */
 8 .boxSiz{
 9     -webkit-box-sizing: border-box;
10     -moz-box-sizing: border-box;
11     -ms-box-sizing: border-box;
12     -o-box-sizing: border-box;
13     box-sizing: border-box;
14 }
15 
16 /* 强制换行 */
17 .toWrap{
18     word-break: break-all;       /* 只对英文起作用,以字母作为换行依据。 */
19     word-wrap: break-word;       /* 只对英文起作用,以单词作为换行依据。*/
20     white-space: pre-wrap;     /* 只对中文起作用,强制换行。*/
21 }
22 
23 /* 禁止换行 */
24 .noWrap{
25     white-space:nowrap;
26 }
27 
28 /* 禁止换行,超出省略号 */
29 .noWrapEllipsis{
30      white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
31 }
32 
33 /* 多行显示省略号,less写法,@line是行数 */
34 .ellipsisLn(@line) {
35     overflow: hidden;
36     text-overflow: ellipsis;
37     display: -webkit-box;
38     -webkit-box-orient: vertical;
39     -webkit-line-clamp: @line;
40 }
41 
42 /* 1px 边框解决方案,示例中设置上边框,可以调整 top、right、bottom、left 的值分别设置上下左右边框 */
43 #box2:after{
44     content: " ";
45     position: absolute;
46     left: 0;
47     top: 0;
48     right: 0;
49     height: 1px;
50     border-top: 1px solid #000;
51     color: #C7C7C7;
52     transform-origin: 0 0;
53     transform: scaleY(0.5);
54 }
55 
56 /* 文字两端对齐 */
57 .text-justify{
58     text-align:justify; 
59     text-justify:inter-ideograph;
60 }
61 
62 /* 定义盒模型为 flex布局兼容写法并让内容水平垂直居中 */
63 .flex-center{
64     display: -webkit-box;
65     display: -moz-box;
66     display: -ms-flexbox;
67     display: -o-box;
68     display: box;
69 
70     -webkit-box-pack: center;
71     -moz-box-pack: center;
72     -ms-flex-pack: center;
73     -o-box-pack: center;
74     box-pack: center;
75 
76     -webkit-box-align: center;
77     -moz-box-align: center;
78     -ms-flex-align: center;
79     -o-box-align: center;
80     box-align: center;
81 }
82 
83 /* public end */

六、flex布局

1、定义弹性盒模型兼容写法

 1 /*
 2     box
 3     inline-box
 4 */
 5 display: -webkit-box;
 6 display: -moz-box;
 7 display: -ms-flexbox;
 8 display: -o-box;
 9 display: box;
10 2、box-orient 定义盒模型内伸缩项目的布局方向
11 
12 /**
13  * vertical column    垂直
14  * horizontal row    水平 默认值
15  */
16 -webkit-box-orient: horizontal;
17 -moz-box-orient: horizontal;
18 -ms-flex-direction: row;
19 -o-box-orient: horizontal;
20 box-orient: horizontal;
21 3、box-direction 定义盒模型内伸缩项目的正序(normal默认值)、倒叙(reverse)
22 
23 /* Firefox */
24 display:-moz-box;
25 -moz-box-direction:reverse;
26 /* Safari、Opera 以及 Chrome */
27 display:-webkit-box;
28 -webkit-box-direction:reverse;
29 4、box-pack 对盒子水平富裕空间的管理
30 
31 /*
32     start
33     end
34     center
35     justify
36 */
37 -webkit-box-pack: center;
38 -moz-box-pack: center;
39 -ms-flex-pack: center;
40 -o-box-pack: center;
41 box-pack: center;
42 5、box-pack 对盒子垂直方向富裕空间的管理
43 
44 /*
45     start
46     end
47     center
48 */
49 /* box-align */
50 -webkit-box-align: center;
51 -moz-box-align: center;
52 -ms-flex-align: center;
53 -o-box-align: center;
54 box-align: center;
55 6、定义伸缩项目的具体位置
56 
57 /*-moz-box-ordinal-group:1;*/ /* Firefox */
58 /*-webkit-box-ordinal-group:1;*/ /* Safari 和 Chrome */
59 .box div:nth-of-type(1){-webkit-box-ordinal-group:1;}
60 .box div:nth-of-type(2){-webkit-box-ordinal-group:2;}
61 .box div:nth-of-type(3){-webkit-box-ordinal-group:3;}
62 .box div:nth-of-type(4){-webkit-box-ordinal-group:4;}
63 .box div:nth-of-type(5){-webkit-box-ordinal-group:5;}
64 7、定义伸缩项目占空间的份数
65 
66 -moz-box-flex:2.0; /* Firefox */
67 -webkit-box-flex:2.0; /* Safari 和 Chrome */
68 
69 .box div:nth-of-type(1){-webkit-box-flex:1;}
70 .box div:nth-of-type(2){-webkit-box-flex:2;}
71 .box div:nth-of-type(3){-webkit-box-flex:3;}
72 .box div:nth-of-type(4){-webkit-box-flex:4;}
73 .box div:nth-of-type(5){-webkit-box-flex:5;}
原文地址

猜你喜欢

转载自www.cnblogs.com/joyco773/p/11457426.html