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 }