移动端重构系列2-html5文档申明

html5文档申明


<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

</body>
</html>

meta标签


<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection"content="telephone=no, email=no" />

viewport

视图窗口,移动端特属的标签。一般使用下面这段代码即可:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;">

上面的代码依次表示设置宽度为设备的宽度,默认不缩放,不允许用户缩放(即禁止缩放),在网页加载时隐藏地址栏与导航栏(ios7.1新增)。

width – // [pixel_value | device-width] viewport 的宽度,范围从 200 到 10,000,默认为 980 像素
height – // [pixel_value | device-height ] viewport 的高度,范围从 223 到 10,000 
initial-scale – // float_value,初始的缩放比例 (范围从 > 0 到 10)
minimum-scale – // float_value,允许用户缩放到的最小比例
maximum-scale – // float_value,允许用户缩放到的最大比例
user-scalable – // [yes | no] 用户是否可以手动缩放
target-densitydpi = [dpi_value | device-dpi | high-dpi | medium-dpi | low-dpi] 目标屏幕像素密度

注:target-densitydpi屏幕像素密度和缩放有关,你可以试试修改这个demo,用手机看下实际效果。我一般不设置这个属性。

apple-mobile-web-app-capable

是否启动webapp功能,会删除默认的苹果工具栏和菜单栏。

<meta name="apple-mobile-web-app-capable" content="yes" />

apple-mobile-web-app-status-bar-style

当启动webapp功能时,显示手机信号、时间、电池的顶部导航栏的颜色。默认值为default(白色),可以定为black(黑色)和black-translucent(灰色半透明)。这个主要是根据实际的页面设计的主体色为搭配来进行设置。

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

telephone & email

忽略页面中的数字识别为电话号码

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

同样还有一个email识别

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

当然两者可以写在一起

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

其他meta

<!-- 启用360浏览器的极速模式(webkit) -->
<meta name="renderer" content="webkit">
<!-- 避免IE使用兼容模式 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑莓 -->
<meta name="HandheldFriendly" content="true">
<!-- 微软的老式浏览器 -->
<meta name="MobileOptimized" content="320">
<!-- uc强制竖屏 -->
<meta name="screen-orientation" content="portrait">
<!-- QQ强制竖屏 -->
<meta name="x5-orientation" content="portrait">
<!-- UC强制全屏 -->
<meta name="full-screen" content="yes">
<!-- QQ强制全屏 -->
<meta name="x5-fullscreen" content="true">
<!-- UC应用模式 -->
<meta name="browsermode" content="application">
<!-- QQ应用模式 -->
<meta name="x5-page-mode" content="app">
<!-- windows phone 点击无高光 -->
<meta name="msapplication-tap-highlight" content="no">

参考资料:

http://www.w3cplus.com/mobile/mobile-terminal-refactoring-create-page.html

link标签

apple-touch-icon

如果apple-mobile-web-app-capable设置为yes了,那么在iPhone,iPad,iTouch的safari上可以使用添加到主屏按钮将网站添加到主屏幕上。而通过设置相应apple-touch-icon标签,则添加到主屏上的图标就会使用我们指定的图片。

以下是针对ox不同设备,选择一个最优icon。默认iphone的大小为60px,ipad为76px,retina屏乘以2倍。

<link rel="apple-touch-icon" href="touch-icon-iphone.png">
<link rel="apple-touch-icon" sizes="76x76" href="touch-icon-ipad.png">
<link rel="apple-touch-icon" sizes="120x120" href="touch-icon-iphone-retina.png">
<link rel="apple-touch-icon" sizes="152x152" href="touch-icon-ipad-retina.png">

ios7以前系统默认会对图标添加特效(圆角及高光),如果不希望系统添加特效,则可以用apple-touch-icon-precomposed.png代替apple-touch-icon.png

图标使用的优先级如下:

  •  如果没有跟相应设备推荐尺寸一致的图标,那个会优先使用比推荐尺寸大,但最接近推荐尺寸的图标。
  •  如果没有比推荐尺寸大的图标,会优先选择最接近推荐尺寸的图标。
  •  如些有多个图标符合推荐尺寸,会优先选择包含关键字precomposed的图标。

如果未在区域指定用link标签指定图标,会自动搜索网站根目录下以apple-touch-icon为前缀的png图标。

注:ios7不再为icon添加特效,ios7以前则默认为icon添加特效,除非icon有关键字-precomposed.png为后缀。

文档模式模板为:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection"content="telephone=no, email=no" />
    <title>Document</title>
</head>
<body>

</body>
</html>

 

posted @ 2014-12-25 17:32  chenguiya  阅读(170)  评论(0)    收藏  举报