前端干货搜集饥人谷技术博客

前端基础05——浏览器兼容

2017-02-08  本文已影响45人  IT男的成长记录

1.浏览器兼容问题

2.相关参考资料

3.处理兼容问题的思路

4. 渐进增强和优雅降级

5. 选择合适的框架合适的框架

6.条件注释

7.CSS hack

.box {
  color: red;   /* 所有浏览器都生效 */
  _color: blue; /* 只有 IE 6 生效 */
  *color: pink; /* 只有 IE 6 IE 7 生效 */
  color: yellow\9; /* IE 6~8 都生效 */
}
< !--[if IE 7]>
<link rel="stylesheet" href="ie7.css" type="text/css" />
<![endif]-->

8.常见属性的兼容情况

9.常见兼容处理范例

.clearfix:after{
  content: '';
  display: block;
  clear: both;
}
.clearfix{
  *zoom: 1;  /* 仅针对ie67有效 */
}
.target {
  /* 在 IE 6,7,8上实现inline-block效果 */
  display: inline-block; /* IE 8生效 */
  /* 一下两句只有在 IE 6,7 上生效,结合产生inline-block效果*/
  *display: inline;
  *zoom: 1;
}

<!--[if IE 7]>
<html class="ie7 no-js">
...
</html>
<![endif]-->
.clearfix {
  /* 在非ie 7 浏览器中,clearfix展现该属性 */
}
.ie7 .clearfix {
   /* 只有ie7浏览器中,clearfix才会展现该属性 */
}

10.兼容性相关的开发工具

11.浏览器兼容的写法

<!--[if IE]>用于 IE <![endif]-->
<!--[if IE 6]>用于 IE6 <![endif]-->
<!--[if IE 7]>用于 IE7 <![endif]-->
<!--[if IE 8]>用于 IE8 <![endif]-->
<!--[if IE 9]>用于 IE9 <![endif]-->
<!--[if gt IE 6]> 用于 IE6 以上版本<![endif]-->
<!--[if lte IE 7]> 用于 IE7或更低版本 <![endif]-->
<!--[if gte IE 8]>用于 IE8 或更高版本 <![endif]-->
<!--[if lt IE 9]>用于 IE9 以下版本<![endif]-->
<!--[if !IE]> -->用于非 IE <!-- <![endif]-->
.box {
  color: red;   /* 所有浏览器都生效 */
  _color: blue; /* 只有 IE 6 生效 */
  *color: pink; /* 只有 IE 6 IE 7 生效 */
  color: yellow\9; /* IE 6~8 都生效 */
}
* Trident内核:主要代表为IE浏览器,前缀为-ms

Gecko内核:主要代表为Firefox,前缀为-moz
Presto内核:主要代表为Opera,前缀为-o
Webkit内核:产要代表为Chrome和Safari,前缀为-webkit

.box {
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    -o-border-radius: 5px;
    border-radius: 5px;
}
<!--[if IE 7]>
<html class="ie7 no-js">
...
</html>
<![endif]-->
.clearfix {
  /* 在非ie 7 浏览器中,clearfix展现该属性 */
}
.ie7 .clearfix {
   /* 只有ie7浏览器中,clearfix才会展现该属性 */
}
<head>      
<meta charset="utf-8">      
<title>My Beautiful Sample Page</title>     
<script src="modernizr-1.5.min.js"></script>  
</head>  
<html class="no-js">
...

页面加载完后的代码

<html class=" js no-flexbox canvas canvastext no-webgl no-touch geolocation 
              postmessage no-websqldatabase no-indexeddb hashchange no-history 
        draganddrop no-websockets rgba hsla multiplebgs backgroundsize 
        no-borderimage borderradius boxshadow no-textshadow opacity 
        no-cssanimations no-csscolumns no-cssgradients no-cssreflections
        csstransforms no-csstransforms3d no-csstransitions fontface 
        generatedcontent video audio localstorage sessionstorage 
        no-webworkers no-applicationcache svg inlinesvg smil svgclippaths">
上一篇下一篇

猜你喜欢

热点阅读