移動端頁面開發遇到的一些問題

1、meta 標籤的相關知識

一、移動端頁面設置視口寬度等於設備寬度,並禁止縮放css

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
複製代碼

二、移動端頁面設置視口寬度等於設備寬度,並禁止縮放,經常使用於微信瀏覽器頁面。html

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

三、禁止將頁面中的數字識別爲電話號碼android

<meta name="format-detection" content="telephone=no" />
複製代碼

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

<meta name="format-detection" content="email=no" />
複製代碼

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

<meta name="apple-mobile-web-app-capable" content="yes" />
<!-- ios7.0版本之後,safari上已看不到效果 -->
複製代碼

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

<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<!-- 可選default、black、black-translucent -->
複製代碼

viewport 模板瀏覽器

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <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>
複製代碼

2、CSS 的樣式技巧

一、禁止 iosandroid 用戶選中文字微信

.css { -webkit-user-select:none }
複製代碼

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

.css { -webkit-touch-callout: none }
複製代碼

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

.css { -webkit-appearance:none; }
複製代碼

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

input::-webkit-input-placeholder{
  color: #aaa;
}

input:focus::-webkit-input-placeholder{
  color: #eee;
}
複製代碼

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

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

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

body {
  -webkit-text-size-adjust: 100%!important;
}
複製代碼

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

input::-webkit-input-speech-button {
  display: none;
}
複製代碼

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

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

3、其餘問題

一、手機拍照和上傳圖片

<!-- 選擇照片 -->
<input type=file accept="image/*">

<!-- 選擇視頻 -->
<input type=file accept="video/*">
複製代碼

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

<input autocapitalize="off" autocorrect="off" />
複製代碼

三、打電話和發短信

<a href="tel:0100-100000">打電話給:0100-100000</a>

<a href="sms:10086">發短信給: 10086</a>
複製代碼

4、CSS reset

@charset "utf-8";
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;
}
 
複製代碼

Normalize.css是一種 CSS reset的替代方案。它在默認的 HTML 元素樣式上提供了跨瀏覽器的高度一致性。相比於傳統的CSS resetNormalize.css是一種現代的、爲HTML5準備的優質替代方案。

Normalize.css的傳送門

5、經常使用公用 CSS style

/* 清除浮動 */
.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;
}
 
/* 文字兩端對齊 */
.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;
}
複製代碼

6、flex彈性佈局

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

/* box inline-box */
.css {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -o-box;
  display: box;
}
複製代碼

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

/** * vertical column 垂直 * horizontal row 水平 默認值 */
.css {
  -webkit-box-orient: horizontal;
  -moz-box-orient: horizontal;
  -ms-flex-direction: row;
  -o-box-orient: horizontal;
  box-orient: horizontal;
}
複製代碼

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

/* Firefox */
.css {
  display: -moz-box;
  -moz-box-direction: reverse;
}
 
/* Safari、Opera 以及 Chrome */
.css {
  display: -webkit-box;
  -webkit-box-direction: reverse;
}
複製代碼

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

/* start end center justify */
.css {
  -webkit-box-pack: center;
  -moz-box-pack: center;
  -ms-flex-pack: center;
  -o-box-pack: center;
  box-pack: center;
}
複製代碼

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

/* start end center */
/* box-align */
.css {
  -webkit-box-align: center;
  -moz-box-align: center;
  -ms-flex-align: center;
  -o-box-align: center;
  box-align: center;
}

複製代碼

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

/*-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;
}
複製代碼

七、定義伸縮項目佔空間的份數

/* -moz-box-flex: 2.0;     Firefox */
/* -webkit-box-flex: 2.0;  Safari 和 Chrome */

.css {
  .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;
  }
}

複製代碼

移動web問題整理

歡迎留言 ~~

相關文章
相關標籤/搜索