META相關javascript
1. 添加到主屏後的標題(IOS)css
<meta name="apple-mobile-web-app-title" content="標題">
2. 啓用 WebApp 全屏模式(IOS)html
當網站添加到主屏幕後再點擊進行啓動時,可隱藏地址欄(從瀏覽器跳轉或輸入連接進入並無此效果)前端
<meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-touch-fullscreen" content="yes" />
3. 百度禁止轉碼html5
經過百度手機打開網頁時,百度可能會對你的網頁進行轉碼,往你頁面貼上它的廣告,很是之噁心。不過咱們能夠經過這個meta標籤來禁止它:java
<meta http-equiv="Cache-Control" content="no-siteapp" />
百度SiteApp轉碼聲明:http://t.cn/R28wSBljquery
4. 設置狀態欄的背景顏色(IOS)android
設置狀態欄的背景顏色,只有在"apple-mobile-web-app-capable" content="yes"
時生效ios
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
content 參數:git
5.移動端手機號碼識別(IOS)
在 iOS Safari (其餘瀏覽器和Android均不會)上會對那些看起來像是電話號碼的數字處理爲電話連接,好比:
可能還有其餘類型的數字也會被識別。咱們能夠經過以下的meta來關閉電話號碼的自動識別:
<meta name="format-detection" content="telephone=no" />
開啓電話功能
<a href="tel:123456">123456</a>
開啓短信功能:
<a href="sms:123456">123456</a>
6. 移動端郵箱識別(Android)
與電話號碼的識別同樣,在安卓上會對符合郵箱格式的字符串進行識別,咱們能夠經過以下的meta來管別郵箱的自動識別:
<meta content="email=no" name="format-detection" />
一樣地,咱們也能夠經過標籤屬性來開啓長按郵箱地址彈出郵件發送的功能:
<a mailto:dooyoe@gmail.com">dooyoe@gmail.com</a>
7. 添加智能 App 廣告條 Smart App Banner(IOS 6+ Safari)
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
8. IOS Web app啓動動畫
因爲iPad 的啓動畫面是不包括狀態欄區域的。因此啓動圖片須要減去狀態欄區域所對應的方向上的20px大小,相應地在retina設備上要減去40px的大小。
<link href="apple-touch-startup-image-320x460.png" media="(device-width: 320px)" rel="apple-touch-startup-image"> <link href="apple-touch-startup-image-640x960.png" media="(device-width: 320px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image"> <link href="apple-touch-startup-image-768x1004.png" media="(device-width: 768px) and (orientation: portrait)" rel="apple-touch-startup-image"> <link href="apple-touch-startup-image-748x1024.png" media="(device-width: 768px) and (orientation: landscape)" rel="apple-touch-startup-image"> <link href="apple-touch-startup-image-1536x2008.png" media="(device-width: 1536px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image"> <link href="apple-touch-startup-image-2048x1496.png" media="(device-width: 1536px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">
(landscape:橫屏
| portrait:豎屏
)
9. 添加到主屏後的APP圖標
指定web app添加到主屏後的圖標路徑,有兩種略微不一樣的方式:
<!-- 設計原圖 --> <link href="short_cut_114x114.png" rel="apple-touch-icon-precomposed"> <!-- 添加高光效果 --> <link href="short_cut_114x114.png" rel="apple-touch-icon">
效果:
圖標尺寸:
可經過指定size屬性來爲不一樣的設備提供不一樣的圖標(但一般來講,咱們只需提供一個114 x 114 pixels大小的圖標便可 )
官方說明以下:
Create different sizes of your app icon for different devices. If you’re creating a universal app, you need to supply app icons in all four sizes. For iPhone and iPod touch both of these sizes are required: 57 x 57 pixels 114 x 114 pixels (high resolution) For iPad, both of these sizes are required: 72 x 72 pixels 144 x 144 (high resolution)
10. 優先使用最新版本 IE 和 Chrome
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
11.viewport模板
<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> <link rel="stylesheet" href="index.css"> </head> <body> 這裏開始內容 </body> </html>
常見問題
一、移動端如何定義字體font-family
三大手機系統的字體:
iOS 系統
Android 系統
默認中文字體是Droidsansfallback
默認英文和數字字體是Droid Sans
Winphone 系統
默認中文字體是Dengxian(方正等線體)
默認英文和數字字體是Segoe
各個手機系統有本身的默認字體,且都不支持微軟雅黑,如無特殊需求,手機端無需定義中文字體,使用系統默認英文字體和數字字體可以使用 Helvetica ,三種系統都支持。
* 移動端定義字體的代碼 */ body{font-family:Helvetica;}
二、移動端字體單位font-size
選擇px
仍是rem
px
便可rem
,例如只須要適配iPhone和iPad等分辨率差異比較挺大的設備rem
配置參考:
html {font-size:10px} @media screen and (min-width:480px) 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) and (max-width:959px) { html { font-size: 25px } } @media screen and (min-width:960px) and (max-width:1079px) { html { font-size: 30px } } @media screen and (min-width:1080px) { html { font-size: 32px }