天天看點

移動端meta設定項詳解

在我們切移動端頁面時,都會對頁面做一些設定。這樣做主要的作用是:避免浏覽器自帶的效果,影響頁面的呈現效果。那麼,有哪些内容需要我們在布局時,進行初始化呢?我們一起來看看。

1、H5頁面視窗自動調整到裝置寬度,并禁止使用者縮放頁面

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

屬性介紹:

width=device-width: 浏覽器頁面的寬度應該等于裝置寬度。

initial-scale: 初始縮放比例,為一個數字,可以帶小數。如果你的網站不是響應式的,請不要使用 initial-scale 或者禁用縮放。

minimum-scale: 允許使用者最小縮放比例,為一個數字,可以帶小數

maximum-scale: 允許使用者最大縮放比例,為一個數字,可以帶小數

user-scalable: 使用者是否可以手動縮放

說明:這項一定要設定,否則你做出的頁面會面目全非,文字、圖檔非常小,跟設計稿完全不符。

2、優先使用 IE 最新版本和 Chrome:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
           

說明:如果你的頁面不考慮低版本浏覽器,那就一定要加上這條語句。

3、防止頁面中的數字被識别為電話号碼。

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

防止不是電話号碼的數字也會被浏覽器自動解析為電話号碼, 并把數字的顔色和樣式都改了。

4、name 屬性的 apple-mobile-web-app-status-bar-style 值(改變頂部狀态條的顔色,是iphone的私有标簽,它指定的iphone中safari頂端的狀态條的樣式;

<meta name="apple-mobile-web-app-status-bar-style" content="black">
           

說明:

(a)在 web app 應用下狀态條(螢幕頂部條)的顔色;

(b)預設值為 default(白色),可以定為 black(黑色)和 black-translucent(灰色半透明);

(c)在定義了apple-mobile-web-app-capable的前提下,設定狀态欄(蘋果狀态欄)的屬性值apple-mobile-web-app-status-bar-style才有效;apple-mobile-web-app-capable是iphone裝置中的safari私有meta标簽,它表示允許全屏模式浏覽;

注意:若值為“black-translucent”将會占據頁面位置,浮在頁面上方(會覆寫頁面 20px 高度 iphone4 和 itouch4 的 Retina 螢幕為 40px )。

5、表示頁面同時适合在移動裝置和PC上進行浏覽

<meta name="applicable-device" content="mobile">
           

接下來,我們一起看看淘寶、京東等大網站,是如何設定meta項的内容。

一、天貓

<title>天貓觸屏版</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" 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">
           

二、淘寶

<title>淘寶網觸屏版</title>
<meta charset="utf-8">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="yes" name="apple-touch-fullscreen">
<meta content="telephone=no" name="format-detection">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta property="wb:webmaster" content="c51923015ca19eb1">
<meta name="author" content="m.taobao.com">
<meta name="copyright" content="Copyright ©m.taobao.com 版權所有">
<meta name="revisit-after" content="1 days">
<meta name="keywords" content="">
<meta name="description" content="">
           

三、京東

<title> 京東 - 手機版 </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;">
<meta name="format-detection" content="telephone=no">
<meta name="Keywords" content="手機購物,WAP商城,日用百貨,3C家電,汽車用品">
<meta name="description" content="京東手機版提供了包括數位、家電、手機、電腦配件、網絡産品、日用百貨等數萬種商品,手機快捷購物,就上京東手機版。">
           

四、網易

<title>手機網易網</title>
<meta charset="UTF-8">
<meta content="width=device-width,user-scalable=no" name="viewport">
<meta name="apple-itunes-app" content="app-id=425349261">
<meta name="apple-mobile-web-app-capable" content="yes">
           

五、百度

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta name="format-detection" content="telephone=no">