手写手机网站

手写手机网站

一般我们自己手动开发手机网站的话,基本可以划分两类来做到。一类是通过在网页头部添加meta标签进行实现(网页指html5的格式来开发)。另一类是通过CSS3的Media标签(媒介查询)来实现。不了解媒介查询的朋友,可以看看这篇文章:响应式布局

在这里我们详细讲解下,利用添加meta标签来做手机网站。

基本在网页头部我们只需添加四个meta标签就可以实现一个手机网站的框架。我一起来看看是哪些meta标签。

1、添加viewport标签

[html] view plain copy
 
  1. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />  

详细属性:

[html] view plain copy
 
  1. width  ----  viewport的宽度(width=device-width意思是:宽度等于设备宽度)  
  2. height ------  viewport的高度(height=device-height意思是:高度等于设备宽度)  
  3. initial-scale ----- 初始的缩放比例  
  4. minimum-scale ----- 允许用户缩放到的最小比例  
  5. maximum-scale ----- 允许用户缩放到的最大比例  
  6. user-scalable ----- 用户是否可以手动缩放  

关于viewport的详细原理和知识点,各位就百度吧!在这里我就不做详细的讲解了。

2、禁止将数字变为电话号码

[html] view plain copy
 
  1. <meta name="format-detection" content="telephone=no" />  

一般情况下,IOS和Android系统都会默认某长度内的数字为电话号码,即使不加也是会默认显示为电话的,so,取消这个很有必要!

3、iphone设备中的safari私有meta标签

[html] view plain copy
 
  1. <meta name="apple-mobile-web-app-capable" content="yes" />  

它表示:允许全屏模式浏览,隐藏浏览器导航栏

4、iphone的私有标签

[html] view plain copy
 
  1. <meta name="apple-mobile-web-app-status-bar-style" content="black">  

它指定的iphone中safari顶端的状态条的样式

默认值为default(白色),可以定为black(黑色)和black-translucent(灰色半透明)

另外还有一个个性化的link标签,它支持用户将网页创建快捷方式到桌面时,其图标变为我们自己定义的图标。比如手机腾讯网上的标签:

[html] view plain copy
 
  1. <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会为这个图标自动添加圆角、阴影和高亮覆盖层,后者则不会添加这些效果。

手机网站基本框架代码:

[html] view plain copy
 
  1. <!doctype html>  
  2. <html>  
  3. <head>  
  4. <meta charset="utf-8">  
  5. <title>手机网站</title>  
  6. <meta name="keywords" content="" />  
  7. <meta name="description" content="" />  
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />  
  9. <meta name="format-detection" content="telephone=no" />  
  10. <meta name="apple-mobile-web-app-capable" content="yes" />  
  11. <meta name="apple-mobile-web-app-status-bar-style" content="black">  
  12. <meta name="author" content="duanliang, duanliang920.com" />  
  13. <style>  
  14.     body{font-size:62.5%;font-family:"Microsoft YaHei",Arial; overflow-x:hidden; overflow-y:auto;}  
  15.     .viewport{ max-width:640px; min-width:300px; margin:0 auto;}  
  16. </style>  
  17.  </head>  
  18.   
  19. <body>  
  20.     <div>  
  21.         大家好!我是段亮,这是我的第一个手机网页哦!  
  22.     </div>  
  23. </body>  
  24. </html>  
posted @ 2018-03-24 20:22  珊瑚231  阅读(166)  评论(0编辑  收藏  举报