移動web開發與pc端的開發仍是有很大的區別的, 雖然移動web可使用一些新的佈局, 如flexbox, 可是由於移動端屏幕尺寸巨多, 而屏幕尺寸又很小, 要充分利用屏幕布局, 所以適配是一個很繁瑣的過程, 針對不一樣的操做系統的特殊處理也比較多, 所以這裏作一個總結.javascript
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
複製代碼
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
複製代碼
<meta name="format-detection" content="telephone=no" />
複製代碼
<meta name="format-detection" content="email=no" />
複製代碼
<meta name="apple-mobile-web-app-capable" content="yes" />
<!-- ios7.0版本之後,safari上已看不到效果 -->
複製代碼
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<!-- 可選default、black、black-translucent -->
複製代碼
<meta name="apple-mobile-web-app-title" content="標題">
複製代碼
<!-- 設計原圖 -->
<link href="short_cut_114x114.png" rel="apple-touch-icon-precomposed">
<!-- 添加高光效果 -->
<link href="short_cut_114x114.png" rel="apple-touch-icon">
複製代碼
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-touch-fullscreen" content="yes" />
複製代碼
<meta http-equiv="Cache-Control" content="no-siteapp" />
複製代碼
移動端字體全部系統都不支持微軟雅黑, 中文使用默認的字體便可, 英文使用Helvetica
可適配絕大部分機型.css
html, body{
font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
}
複製代碼
html{font-size:10px}
@media screen and (min-width:321px) and (max-width:375px){html{font-size:11px}}
@media screen and (min-width:376px) and (max-width:414px){html{font-size:12px}}
@media screen and (min-width:415px) and (max-width:639px){html{font-size:15px}}
@media screen and (min-width:640px) and (max-width:719px){html{font-size:20px}}
@media screen and (min-width:720px) and (max-width:749px){html{font-size:22.5px}}
@media screen and (min-width:750px) and (max-width:799px){html{font-size:23.5px}}
@media screen and (min-width:800px){html{font-size:25px}}
複製代碼
TouchEventhtml
參數信息(changedTouches[0])java
使用fastclickjs
, 或者zeptojs
的tap
事件, 這算是移動端適配的基本技巧了, 而實際上我在fastclick
的README.md中看到下面這段話android
Note: As of late 2015 most mobile browsers - notably Chrome and Safari - no longer have a 300ms touch delay, so fastclick offers no benefit on newer browsers, and risks introducing bugs into your application. Consider carefully whether you really need to use it. 注意:截至2015年末,大多數移動瀏覽器(尤爲是Chrome和Safari)再也不具備300毫秒的觸摸延遲,所以fastclick對新瀏覽器沒有任何好處,而且可能會在您的應用程序中引入錯誤。仔細考慮您是否真的須要使用它。ios
// fastclick
<script type='application/javascript' src='/path/to/fastclick.js'></script>
<script type='application/javascript'>
window.addEventListener('load', function() {
new FastClick(document.body);
}, false);
</script>
複製代碼
a,button,input,textarea{-webkit-tap-highlight-color: rgba(0,0,0,0;)}
複製代碼
a,button,input,textarea{
-webkit-tap-highlight-color: rgba(0,0,0,0;)
-webkit-user-modify:read-write-plaintext-only;
}
複製代碼
<input autocapitalize="off" autocorrect="off" />
複製代碼
# 電話
<a href="tel:0755-10086">打電話給:0755-10086</a>
# 短信
<a href="sms:10086">發短信給: 10086</a>
# 郵件
<a href="mailto:xxx@foxmail.com">xxx@foxmail.com</a>
複製代碼
列出個人初始化樣式文件git
@charset "utf-8";
/*禁止文字縮放 字體設置 取消touch高亮效果*/
html{
min-width:320px;
max-width:640px;
margin:0 auto;
-webkit-text-size-adjust:100%; /*關閉橫屏時字體大小自動調整功能.*/
background:transparent;
font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;;
-webkit-tap-highlight-color:rgba(0,0,0,0);
}
body{
width:100%;
height:100%;
-webkit-overflow-scrolling: touch; /*快速滾動和回彈的效果*/
}
article,aside,dialog,footer,header,section,footer,nav,figure,a{
display:block;
}
body, div, span, header, footer, nav, section, aside, article, ul, dl, dt, dd, li, a, p, h1, h2, h3, h4,h5, h6, i, b,
textarea, button, input, select, figure, figcaption, ol, pre, fieldset, legend, blockquote {
margin:0;
padding:0;
}
fieldset, img ,button{
border: none;
outline:none;
}
/*去除單元格之間的距離*/
table{
border-collapse:collapse;
border-spacing:0;
}
/*清除輸入框內陰影*/
input,select,textarea{
border:none;
-webkit-appearance:none; /*去除系統默認appearance的樣式,經常使用於IOS下移除原生樣式*/
appearance:none;
}
/*chrome表單自動填充去掉input黃色背景*/
input:-webkit-autofill,textarea:-webkit-autofill,select:-webkit-autofill{
-webkit-box-shadow:0 0 0px 1000px white inset;
}
ul,ol,dd,dt,dl{
list-style-type:none;
}
i,em{
font-style:normal;
}
/*禁止長按頁面彈出菜單(iOS)*/
img,a{
-webkit-touch-callout:none;
}
a,a:active,a:hover{
text-decoration:none;
}
/*去掉點擊連接和文本框對象時默認的灰色半透明覆蓋層(iOS)或者虛框(Android)*/
a, button, input, textarea, select{
-webkit-tap-highlight-color:transparent;
-webkit-border-radius:0;
}
複製代碼