- DOCTYPE
- charset
- lang属性
- 优先使用IE最新版本和Chrome
- 360浏览器
- 禁止百度转码
- SEO优化
- Viewport
- 移动端字体
- iOS 设备
- iOS 图标
- iOS 启动画面
- Windows 8
- rss订阅
- favicon icon
- 移动端meta
DOCTYPE
HTML5
- 对文档进行有效性验证
- 决定浏览器的呈现模式
<!DOCTYPE html>
charset
声明文档使用的字符编码
<meta charset="utf-8">
lang属性
- 简体中文
<html lang="zh-CN">
- 英文
<html lang="en">
优先使用IE最新版本和Chrome
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
360浏览器
读取到这个标签后会立即切换对应的极速核
<meta name="renderer" content="webkit">
为了保险起见再加入上一种标签,如果安装了Google Chrome Frame,就使用GCF来渲染页面;如果没有安装 GCF,则使用最高版本的IE内核进行渲染。
禁止百度转码
<meta http-equiv="Cache-Control" content="no-siteapp">
SEO优化
页面标题title
标签
<title>your title</title>
网页作者 author
<meta name="author" content="author, email address">
页面描述内容 description
<meta name="description" content="your description">
页面关键词 keywords
<meta name="keywords" content="your keywords">
Viewport
通常写成
<meta name="viewport" content="width=device-width, initial-scale=1">
width=device-width
会导致在 iPhone 5 中网页被添加到主屏后,以WebApp全屏模式打开时出现黑边
content参数:
-
width
Viewport宽度(数值/device-width) -
height
Viewport高度(数值/device-height) -
initial-scale
初始缩放比例 -
maximum-scale
最大缩放比例 -
minimum-scale
最小缩放比例 -
user-scalable
是否允许用户缩放(yes/no) -
minimal-ui
在页面加载时最小化状态栏,布尔值 -
如果网站不是响应式的,不要使用
initial-scale
者禁用缩放。
H5页面窗口自动调整到设备宽度,并禁止用户缩放页面
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
适配 iPhone 6 和 iPhone 6 plus
<meta name="Viewport" content="width=375">
<meta name="Viewport" content="width=414">
大部分 4.7~5 寸安卓设备的 Viewport 宽设为 360px,iPhone 6 为 375px
大部分 5.5 寸安卓设备(三星 Note)的 Viewport 宽为 400,iPhone 6 plus 为 414px
移动端字体
font-family: 中文字体使用系统默认字体,英文用Helvetica
font-size单位选择
-
只需要适配少部分手机设备,且分辨率对页面影响不大的,使用px
-
对于需要适配各种移动设备,使用rem,例如需要适配iPhone和iPad等分辨率差别比较大的设备
-
rem配置参考:
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}
iOS 设备
添加到主屏后的标题
<meta name="apple-mobile-web-app-title" content="标题">
是否启用 WebApp 全屏模式
<meta name="apple-mobile-web-app-capable" content="yes">
设置状态栏的背景颜色,只有在"apple-mobile-web-app-capable" content="yes"
时生效
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
content
参数
-
default
默认值 -
black
黑色 -
black-translucent
黑色半透明 -
如果设置为
default
或black
,网页内容从状态栏底部开始;如果设置为black-translucent
,网页内容充满整个屏幕,顶部会被状态栏遮挡
禁止数字识自动别为电话号码
<meta name="format-detection" content="telephone=no">
iOS 图标
rel 参数
-
apple-touch-icon
图片自动处理成圆角和高光等效果 -
apple-touch-icon-precomposed
禁止系统自动添加效果,显示设计原图
iPhone 和 iTouch,默认 57x57 像素
<link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57x57-precomposed.png">
iPad,72x72 像素
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/apple-touch-icon-72x72-precomposed.png">
Retina iPhone 和 Retina iTouch,114x114 像素
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114-precomposed.png">
Retina iPad,144x144 像素
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144-precomposed.png">
iPhone 6,120x120 像素;iPhone 6 plus,180×180 像素
<link rel="apple-touch-icon-precomposed" sizes="180x180" href="retinahd_icon.png">
iOS 启动画面
iPad 的启动画面不包括状态栏区域
- iPad 竖屏 1536x2008(Retina)
<link rel="apple-touch-startup-image" sizes="1536x2008" href="/splash-screen-1536x2008.png">
- iPad 横屏 2048x1496(Retina)
<link rel="apple-touch-startup-image" sizes="2048x1496" href="/splash-screen-2048x1496.png">
iPhone 和 iPod touch 的启动画面包含状态栏区域
- iPhone/iPod Touch 竖屏 640x960 (Retina)
<link rel="apple-touch-startup-image" sizes="640x960" href="/splash-screen-640x960.png">
iPhone 5/iPod Touch 5 竖屏 640x1136 (Retina)
<link rel="apple-touch-startup-image" sizes="640x1136" href="/splash-screen-640x1136.png">
iPhone 6 竖屏 750×1294,iPhone 6 Plus 竖屏 1242×2148
<link rel="apple-touch-startup-image" href="launch6.png" media="(device-width: 375px)">
<link rel="apple-touch-startup-image" href="launch6plus.png" media="(device-width: 414px)">
添加智能 App 广告条 Smart App Banner(iOS 6+ Safari)
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
Windows 8
Windows 8 磁贴颜色
<meta name="msapplication-TileColor" content="#000">
Windows 8 磁贴图标
<meta name="msapplication-TileImage" content="icon.png">
rss订阅
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml">
favicon icon
<link rel="shortcut icon" type="image/ico" href="/favicon.ico">
移动端meta
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">