移动端适配

183 阅读2分钟
媒体查询
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="/style.css" media="only screen and( max-width:320px)">  
		'屏幕最大宽度之内调用link '

		<style>
			@media(min-width: 100px) and (max-width: 980px) {
				body{
					background: black;
				}
				
			}
			@media  (min-width:980px ) {
				body{
					background: red;
				}			
			}
			
		</style>
	</head>
	<body>
		
	</body>
</html>


2

1、移动网站要加的html5相关meta和标签
    a、<!-- 强制让文档与设备的宽度保持1:1 -->
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    网页宽度默认等于屏幕宽度(width=device-width),
    初始缩放比例(initial-scale=1)为1.0,即网页初始大小占屏幕面积的100%。


    b、<!-- 删除默认的苹果工具栏和菜单栏 -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    c、<!-- 在web app应用下状态条(屏幕顶部条)的颜色 -->
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    d、<!-- 禁止了把数字转化为拨号链接 -->
    <meta name="format-detection" content="telephone=no">
    e、<!-- 浏览网站时的小图标 -->
    <link rel="shortcut icon" href="http://p.www.xiaomi.com/favicon.ico" type="/image/x-icon">  
    f、<!-- 添加至主屏时的图片 -->
    <link rel="apple-touch-icon-precomposed" href="http://a.tbcdn.cn/mw/s/hi/tbtouch/images/touch-icon.png">


    ==================
    还有一种有趣的方法
    创建html5时发现这么一句话,如下:
    <meta http-equiv=”X-UA-Compatible” content=”IE=edge,chrome=1″/>


    这样写可以达到的效果是如果安装了GCF(Google Chrome Frame 谷歌内嵌浏览器框架的简称),则使用GCF来渲染页面,如果没安装GCF,则使用最高版本的IE内核进行渲染。这个插件可以让用户的IE浏览器外不变,但用户在浏览网页时,实际上使用的是Google Chrome浏览器内核,而且支持IE6、7、8等多个版本的IE浏览器。