浏览器兼容

2017-03-13  本文已影响0人  ychenxi

什么是 CSS hack

box{
 color: red; /*firefox 或 chrome 浏览器下是红色*/
_color: blue; /*ie6*/
 *color: pink; /*ie67*/ 
color: yellow\9; /*ie6~ie10*/
}

github CSS hack

谈一谈浏览器兼容的思路

  1. 要不要做:
  1. 做到什么程度:
    兼容到哪个最低版本的浏览器。是IE8还是要包括IE67。

  2. 如何做:

列举5种以上浏览器兼容的写法

  1. 清除浮动
.clearfix:after{
  content: '';
  display: block;
  clear: both;
  }
.clearfix{
   *zoom: 1; /* 仅对ie67有效 */
  } 
  1. inline-block的ie67兼容
.target{
  display: inline-block;
  *display: inline;
  *zoom: 1;
}
  1. 使用 respond.jshtml5shiv.js
<!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
  1. 使用条件注释
<!DOCTYPE html><!--[if IEMobile 7 ]> <html dir="ltr" lang="en-US"class="no-js iem7"> <![endif]--><!--[if lt IE 7 ]> <html dir="ltr" lang="en-US" class="no-js ie6 oldie"> <![endif]--><!--[if IE 7 ]> <html dir="ltr" lang="en-US" class="no-js ie7 oldie"> <![endif]--><!--[if IE 8 ]> <html dir="ltr" lang="en-US" class="no-js ie8 oldie"> <![endif]--><!--[if (gte IE 9)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html dir="ltr" lang="en-US" class="no-js"><!--<![endif]-->
  1. 使用 Autoprefixer 生成主流浏览器前缀。
    http://autoprefixer.github.io/

以下工具/名词是做什么的

<!--[if !IE]><!-->
    <script>alert(1);</script>
    <!--<![endif]-->
<!–除IE外都可识别(IE10版本以上也可以识别)–>
<!--[if IE 6]>
    <p>You are using Internet Explorer 6.</p>
    <![endif]-->
<!–仅IE6可识别–>
<!--[if IE 8]>
    <link href="ie8only.css" rel="stylesheet">
    <![endif]-->
<!–仅IE8可识别–>
<!--[if lt IE 6]>
<![endif] -->
<!–IE6以下版本可识别–>
<!-- [if lte IE 8]>
<![endif] -->
<!–IE8以及IE8以下版本可识别–>
<!-- [if gt IE 7]>
<![endif] -->
<!–IE7以上版本可识别–>
<!--[if gte IE 6]>
<![endif]-->
<!–IE6以及IE6以上版本可识别–>
<!--[if (IE 6)|(IE 7)]>
<![endif]-->
<!–IE6或者IE7版本可识别–>

一般在哪个网站查询属性兼容性?

http://caniuse.com/#home

上一篇 下一篇

猜你喜欢

热点阅读