標籤:
一.Meta標籤
<meta name="apple-touch-fullscreen" content="yes">"添加到主畫面“後,全螢幕顯示 <meta name="apple-mobile-web-app-capable" content="yes" />
這meta的作用就是刪除預設的蘋果工具列和功能表列。content有兩個值”yes”和”no”,當我們需要顯示工具列和功能表列時,這個行meta就不用加了,預設就是顯示。
<meta name=”apple-mobile-web-app-status-bar-style” content=black” />
預設值為default(白色),可以定為black(黑色)和black-translucent(灰色半透明)。
注意: 若值為“black-translucent”將會佔據頁面px位置,浮在頁面上方(會覆蓋頁面20px高度–iphone4和itouch4的Retina螢幕為40px)。
在iOS中有兩個meta值,apple-mobile-web-app-capable和apple-mobile-web-app-status-bar-style,這兩個會讓網頁內容以應用程式風格顯示,並使狀態列透明。
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<link rel="apple-touch-icon-precomposed" href="http://spion.blog.163.com/blog/iphone_milanoo.png" />
說明: 這個link就是設定web app的放置主畫面上icon檔案路徑。
圖片尺寸可以設定為57*57(px)或者Retina可以定為114*114(px),ipad尺寸為72*72(px)
<meta content="telephone=no" name="format-detection" />
<meta content="email=no" name="format-detection" />//將不識別郵箱
告訴裝置忽略將頁面中的數字識別為電話號碼
iOS用rel="apple-touch-icon",android 用rel="apple-touch-icon-precomposed"。這樣就能在使用者把網頁存為書籤時,在手機HOME介面建立應用程式樣式的表徵圖。
<link rel="apple-touch-icon" href="/static/images/identity/HTML5_Badge_64.png" />
<link rel="apple-touch-icon-precomposed" href="/static/images/identity/HTML5_Badge_64.png" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0">
參考文獻:http://www.w3school.com.cn/html5/html5_meta.asp
二. Meta元素可視區
預設情況下,iPhone上的Safari會象在大螢幕的案頭瀏覽器那樣顯示你的頁面,寬度達到了980像素,然後縮小內容以適應iPhone的小螢幕,因此使用者在iPhone看這個頁面時感覺字型就比較小了,也比較模糊,必須要放大才能看得真切,對於一個普通的Web頁面似乎可以接受,但對於一個常用的應用程式就沒幾個人能夠受得了。
幸運的是可以使用特殊的Meta元素可視區進行糾正:
<meta name="viewport" content="width=device-width"/>
這個元素通知瀏覽器使用裝置的寬度作為可視區的寬度,而不是預設的980像素了,我們可以看看兩個不同的例子。
例3(連結:http://www.sitepoint.com/examples/iphone-development-12tips/no-viewport.html)顯示了一個簡單的段落元素,沒有Meta元素可視區,字型有點模糊。在iPhone中啟動並執行實際情況如所示。
圖 1 無可視區的顯示效果
例4(連結:http://www.sitepoint.com/examples/iphone-development-12tips/viewport.html)包括了一個可視區元素,現在裝置寬度只有320像素,字型也比前一個例子更清晰了。在iPhone中啟動並執行實際情況如所示。
圖 2 有可視區的顯示效果
另外,你還可以手動設定device-width的值,例如,假設你的部落格頁面的寬度是750像素,那麼案頭螢幕最佳大小就是800x600像素,例5(連結:http://www.sitepoint.com/examples/iphone-development-12tips/fixed750.html)顯示了一個刪減版本,如果你在iPhone中瀏覽它,你會看到980像素剩下的空間都填充了白色。
為了消除額外的空間,可以使用meta元素可視區將寬度設為780像素:
<meta name="viewport" content="width=780"/>
例6(連結:http://www.sitepoint.com/examples/iphone-development-12tips/fixed750-viewport.html)顯示了meta元素可視區布局被固定後的效果。
Meta元素可視區的內容可以包括多個逗號分隔的值,如initial-scale – 使用者最初看到頁面時的放大層級,對於Web應用程式,一個常見的設定是:
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/>
這個元素設定寬度為裝置的最大寬度,禁止使用者放大和縮小
WebApp之Meta標籤