日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

發布時間:2025/3/19 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [转]移动端页面开发资源总结及技巧 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

工作了有一段時間,基本上都在搞移動端的前端開發,工作的過程中遇到過很多問題,bug的解決方案,記錄下來,以便后用!!!內容并不是很全,以后每遇到一個問題都會總結在這里,分享給大家!

一、meta標簽相關知識

1、移動端頁面設置視口寬度等于設備寬度,并禁止縮放。

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),并禁止縮放,常用于微信瀏覽器頁面。

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

3、禁止將頁面中的數字識別為電話號碼

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

4、忽略Android平臺中對郵箱地址的識別

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

5、當網站添加到主屏幕快速啟動方式,可隱藏地址欄,僅針對ios的safari

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

6、將網站添加到主屏幕快速啟動方式,僅針對ios的safari頂端狀態條的樣式

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

viewport莫板

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

<body>
content...
</body>

</html>

二、CSS樣式技巧

1、禁止ios和android用戶選中文字

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

2、禁止ios長按時觸發系統的菜單,禁止ios&android長按時下載圖片

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

3、webkit去除表單元素的默認樣式

1 .css{-webkit-appearance:none;}

4、修改webkit表單輸入框placeholder的樣式

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

5、去除android a/button/input標簽被點擊時產生的邊框 & 去除ios a標簽被點擊時產生的半透明灰色背景

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

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

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

7、android 上去掉語音輸入按鈕

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

8、移動端定義字體,移動端沒有微軟雅黑字體

1
2
/* 移動端定義字體的代碼 */
body{font-family:Helvetica;}

9、禁用Webkit內核瀏覽器的文字大小調整功能。

1 -webkit-text-size-adjust: none;

三、其他技巧

1、手機拍照和上傳圖片

1
2
3
4
<!-- 選擇照片 -->
<input type=file accept="image/*">
<!-- 選擇視頻 -->
<input type=file accept="video/*">

2、取消input在ios下,輸入的時候英文首字母的默認大寫

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

3、打電話和發短信

1
2
<a href="tel:0755-10086">打電話給:0755-10086</a>
<a href="sms:10086">發短信給: 10086</a>

四、CSS reset

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* hcysun */
@charset "utf-8";
/* reset */
html{
-webkit-text-size-adjust:none;
-webkit-user-select:none;
-webkit-touch-callout: none
font-family: Helvetica;
}
body{font-size:12px;}
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;}
a,button,input,textarea,select{ background: none; -webkit-tap-highlight-color:rgba(255,0,0,0); outline:none; -webkit-appearance:none;}
em{font-style:normal}
li{list-style:none}
a{text-decoration:none;}
img{border:none; vertical-align:top;}
table{border-collapse:collapse;}
textarea{ resize:none; overflow:auto;}
/* end reset */

五、常用公用CSS style

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* public */

/* 清除浮動 */
.clear { zoom:1; }
.clear:after { content:''; display:block; clear:both; }

/* 定義盒模型為怪異和模型(寬高不受邊框影響) */
.boxSiz{
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
box-sizing: border-box;
}

/* 強制換行 */
.toWrap{
word-break: break-all; /* 只對英文起作用,以字母作為換行依據。 */
word-wrap: break-word; /* 只對英文起作用,以單詞作為換行依據。*/
white-space: pre-wrap; /* 只對中文起作用,強制換行。*/
}

/* 禁止換行 */
.noWrap{
white-space:nowrap;
}

/* 禁止換行,超出省略號 */
.noWrapEllipsis{
white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}

/* 多行顯示省略號,less寫法,@line是行數 */
.ellipsisLn(@line) {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: @line;
}

/* 1px 邊框解決方案,示例中設置上邊框,可以調整 top、right、bottom、left 的值分別設置上下左右邊框 */
#box2:after{
content: " ";
position: absolute;
left: 0;
top: 0;
right: 0;
height: 1px;
border-top: 1px solid #000;
color: #C7C7C7;
transform-origin: 0 0;
transform: scaleY(0.5);
}

/* 文字兩端對齊 */
.text-justify{
text-align:justify;
text-justify:inter-ideograph;
}

/* 定義盒模型為 flex布局兼容寫法并讓內容水平垂直居中 */
.flex-center{
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -o-box;
display: box;

-webkit-box-pack: center;
-moz-box-pack: center;
-ms-flex-pack: center;
-o-box-pack: center;
box-pack: center;

-webkit-box-align: center;
-moz-box-align: center;
-ms-flex-align: center;
-o-box-align: center;
box-align: center;
}

/* public end */

六、flex布局

1、定義彈性盒模型兼容寫法

1
2
3
4
5
6
7
8
9
10

/*
box
inline-box
*/
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -o-box;
display: box;

2、box-orient 定義盒模型內伸縮項目的布局方向

1
2
3
4
5
6
7
8
9
/**
* vertical column 垂直
* horizontal row 水平 默認值
*/
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
-ms-flex-direction: row;
-o-box-orient: horizontal;
box-orient: horizontal;

3、box-direction 定義盒模型內伸縮項目的正序(normal默認值)、倒敘(reverse)

1
2
3
4
5
6
/* Firefox */
display:-moz-box;
-moz-box-direction:reverse;
/* Safari、Opera 以及 Chrome */
display:-webkit-box;
-webkit-box-direction:reverse;

4、box-pack 對盒子水平富裕空間的管理

1
2
3
4
5
6
7
8
9
10
11
/*
start
end
center
justify
*/
-webkit-box-pack: center;
-moz-box-pack: center;
-ms-flex-pack: center;
-o-box-pack: center;
box-pack: center;

5、box-pack 對盒子垂直方向富裕空間的管理

1
2
3
4
5
6
7
8
9
10
11
/*
start
end
center
*/
/* box-align */
-webkit-box-align: center;
-moz-box-align: center;
-ms-flex-align: center;
-o-box-align: center;
box-align: center;

6、定義伸縮項目的具體位置

1
2
3
4
5
6
7
/*-moz-box-ordinal-group:1;*/ /* Firefox */
/*-webkit-box-ordinal-group:1;*/ /* Safari 和 Chrome */
.box div:nth-of-type(1){-webkit-box-ordinal-group:1;}
.box div:nth-of-type(2){-webkit-box-ordinal-group:2;}
.box div:nth-of-type(3){-webkit-box-ordinal-group:3;}
.box div:nth-of-type(4){-webkit-box-ordinal-group:4;}
.box div:nth-of-type(5){-webkit-box-ordinal-group:5;}

7、定義伸縮項目占空間的份數

1
2
3
4
5
6
7
8
-moz-box-flex:2.0; /* Firefox */
-webkit-box-flex:2.0; /* Safari 和 Chrome */

.box div:nth-of-type(1){-webkit-box-flex:1;}
.box div:nth-of-type(2){-webkit-box-flex:2;}
.box div:nth-of-type(3){-webkit-box-flex:3;}
.box div:nth-of-type(4){-webkit-box-flex:4;}
.box div:nth-of-type(5){-webkit-box-flex:5;}
來源: 移動端頁面開發資源總

?

總結

以上是生活随笔為你收集整理的[转]移动端页面开发资源总结及技巧的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。