手机网站 meta标签
在这里我们详细讲解下,利用添加meta标签来做手机网站。
基本在网页头部我们只需添加四个meta标签就可以实现一个手机网站的框架。我一起来看看是哪些meta标签。
1、添加viewport标签
- <meta name=“viewport” content=“width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0” />
详细属性:
- width —- viewport的宽度(width=device-width意思是:宽度等于设备宽度)
- height —— viewport的高度(height=device-height意思是:高度等于设备宽度)
- initial-scale —– 初始的缩放比例
- minimum-scale —– 允许用户缩放到的最小比例
- maximum-scale —– 允许用户缩放到的最大比例
- user-scalable —– 用户是否可以手动缩放
什么是 Viewport?
viewport 是用户网页的可视区域。
viewport 翻译为中文可以叫做”视区”。
手机浏览器是把页面放在一个虚拟的”窗口”(viewport)中,通常这个虚拟的”窗口”(viewport)比屏幕宽,这样就不用把每个网页挤到很小的窗口中(这样会破坏没有针对手机浏览器优化的网页的布局),用户可以通过平移和缩放来看网页的不同部分。
设置 Viewport
一个常用的针对移动网页优化过的页面的 viewport meta 标签大致如下:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- width:控制 viewport 的大小,可以指定的一个值,如 600,或者特殊的值,如 device-width 为设备的宽度(单位为缩放为 100% 时的 CSS 的像素)。
- height:和 width 相对应,指定高度。
- initial-scale:初始缩放比例,也即是当页面第一次 load 的时候缩放比例。
- maximum-scale:允许用户缩放到的最大比例。
- minimum-scale:允许用户缩放到的最小比例。
- user-scalable:用户是否可以手动缩放。
2、禁止将数字变为电话号码和邮箱
- <meta name=“format-detection” content=“telephone=no” />
一般情况下,IOS和Android系统都会默认某长度内的数字为电话号码,即使不加也是会默认显示为电话的,so,取消这个很有必要!
2.<meta name=”format-detection” content=”email=no”/>
说明:忽略页面中的邮箱格式为邮箱
合起来就是:<meta name=“format-detection” content=“telphone=no, email=no”/>
3、iphone设备中的safari私有meta标签
- <meta name=“apple-mobile-web-app-capable” content=“yes” />
<!– 删除默认的苹果工具栏和菜单栏 –>
它表示:允许全屏模式浏览,隐藏浏览器导航栏
4、iphone的私有标签
- <meta name=“apple-mobile-web-app-status-bar-style” content=“black”>
它指定的iphone中safari顶端的状态条的样式
默认值为default(白色),可以定为black(黑色)和black-translucent(灰色半透明)
另外还有一个个性化的link标签,它支持用户将网页创建快捷方式到桌面时,其图标变为我们自己定义的图标。比如手机腾讯网上的标签:
- <link rel=“apple-touch-icon-precomposed” href=“http://3gimg.qq.com/wap30/info/info5/img/logo_icon.png”>
不过腾讯对这个png图标的命名并不规范,常规我们要求文件名应为 apple-touch-icon.png 或 apple-touch-icon-precomposed.png ,前者的命名iOS会为这个图标自动添加圆角、阴影和高亮覆盖层,后者则不会添加这些效果。
5、name之设置作者姓名及联系方式
<meta name=”author” contect=”name, xxx@163.com” />
6、其他meta
<!– 声明文档使用的字符编码 –>
<meta charset=’utf-8′>
<!– 优先使用 IE 最新版本和 Chrome –>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge,chrome=1″/>
<!– 页面描述 –>
<meta name=”description” content=”不超过150个字符”/>
<!– 页面关键词 –>
<meta name=”keywords” content=””/>
<!– 搜索引擎抓取 –>
<meta name=”robots” content=”index,follow”/>
<!– 启用360浏览器的极速模式(webkit) –>
<meta name=”renderer” content=”webkit”>
<!– 避免IE使用兼容模式 –>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<!– 不让百度转码 –>
<meta http-equiv=”Cache-Control” content=”no-siteapp” />
<!– 针对手持设备优化,主要是针对一些老的不识别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”>
<!– 添加 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”/>
<!– sns 社交标签 begin –>
<!– 参考微博API –>
<meta property=”og:type” content=”类型” />
<meta property=”og:url” content=”URL地址” />
<meta property=”og:title” content=”标题” />
<meta property=”og:image” content=”图片” />
<meta property=”og:description” content=”描述” />
<!– sns 社交标签 end –>
<!– Windows 8 磁贴颜色 –>
<meta name=”msapplication-TileColor” content=”#000″/>
<!– Windows 8 磁贴图标 –>
<meta name=”msapplication-TileImage” content=”icon.png”/>
<!– windows phone 点击无高光 –>
<meta name=”msapplication-tap-highlight” content=”no”>
手机网站基本框架代码:
- <!doctype html>
- <html>
- <head>
- <meta charset=“utf-8”>
- <title>手机网站</title>
- <meta name=“keywords” content=“” />
- <meta name=“description” content=“” />
- <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=“apple-mobile-web-app-capable” content=“yes” />
- <meta name=“apple-mobile-web-app-status-bar-style” content=“black”>
- <meta name=“author” content=“duanliang, duanliang920.com” />
- <style>
- body{font-size:62.5%;font-family:”Microsoft YaHei”,Arial; overflow-x:hidden; overflow-y:auto;}
- .viewport{ max-width:640px; min-width:300px; margin:0 auto;}
- </style>
- </head>
- <body>
- <div>
- 大家好!我是段亮,这是我的第一个手机网页哦!
- </div>
- </body>
- </html>
合集:
- <!–[if lt IE 7 ]><html class=”oldie ie ie6″> <![endif]–>
- <!–[if IE 7 ]><html class=”oldie ie ie7″> <![endif]–>
- <!–[if IE 8 ]><html class=”ie ie8″> <![endif]–>
- <!–[if (gte IE 9)|!(IE)]><!–><html> <!–<![endif]–>
- <head>
- <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>
- <title></title>
- <meta name=“keywords” content=“” />
- <meta name=“description” content=“” />
- <meta name=“title” content=“” />
- <meta name=“author” content=“-06” />
- <meta name=“Copyright” content=“” />
- <!– 让IE浏览器用最高级内核渲染页面 还有用 Chrome 框架的页面用webkit 内核
- ================================================== —>
- <meta http-equiv=“X-UA-Compatible” content=“IE=edge,chrome=1”>
- <!– IOS6全屏 Chrome高版本全屏
- ================================================== —>
- <meta name=“apple-mobile-web-app-capable” content=“yes”>
- <meta name=“mobile-web-app-capable” content=“yes”>
- <!– 让360双核浏览器用webkit内核渲染页面
- ================================================== —>
- <meta name=“renderer” content=“webkit”>
- <!– Mobile Specific Metas
- ================================================== —>
- <!– !!!注意 minimal-ui 是IOS7.1的新属性,最小化浏览器UI –>
- <meta name=“viewport” content=“width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui”>
- <meta name=“format-detection” content=“telephone=no”>
- <!– CSS
- ================================================== —>
- <link href=“/css/reset.css” rel=“stylesheet” type=“text/css”>
- <link href=“/css/magicwall.css” rel=“stylesheet” type=“text/css”>
- <link href=“/css/jquery.gridster.css” rel=“stylesheet” type=“text/css”>
- <link href=“/css/case.css” rel=“stylesheet” type=“text/css”>
- <link href=“/css/case_1280.css” rel=“stylesheet” type=“text/css”>
- <link href=“/css/case_1024.css” rel=“stylesheet” type=“text/css”>
- <link href=“/css/case_640.css” rel=“stylesheet” type=“text/css”>
- <link href=“/css/case_320.css” rel=“stylesheet” type=“text/css”>
- <link href=“/css/style_retina.css” rel=“stylesheet” type=“text/css”>
- <!–[if lt IE 9]>
- <script src=“http://cdn.bootcss.com/html5shiv/r29/html5.js”></script>
- <![endif]–>
- <!– Favicons
- ================================================== —>
- <link rel=“shortcut icon” href=“favicon.ico” >
- <!– Android 主屏图标
- ================================================== —>
- <link rel=“icon” sizes=“196×196” href=“/images/apple-touch-icon-152×152.png”>
- <!– IOS 主屏图标
- ================================================== —>
- <link rel=“apple-touch-icon-precomposed” href=“/images/apple-touch-icon-76×76.png”>
- <link rel=“apple-touch-icon-precomposed” sizes=“76×76” href=“/images/apple-touch-icon-76×76.png”>
- <link rel=“apple-touch-icon-precomposed” sizes=“120×120” href=“/images/apple-touch-icon-120×120.png”>
- <link rel=“apple-touch-icon-precomposed” sizes=“152×152” href=“/images/apple-touch-icon-152×152.png”>
- <link rel=“apple-touch-startup-image” href=“/startup-748×1024.jpg”
- media=“screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)” >
- <link rel=“apple-touch-startup-image” href=“/startup-768×1004.jpg”
- media=“screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)” >
- <!– 启用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”>
参考网址:https://blog.csdn.net/kongjiea/article/details/17092413
附:
1、<!– 浏览网站时的小图标 –>
<link rel=”shortcut icon” href=”http://p.www.xiaomi.com/favicon.ico” type=”/image/x-icon”>
2、<!– 添加至主屏时的图片 –>
<link rel=”apple-touch-icon-precomposed” href=”http://a.tbcdn.cn/mw/s/hi/tbtouch/images/touch-icon.png”>