饥人谷技术博客

浏览器兼容的部分问题

2017-08-05  本文已影响0人  汤初景

什么是 CSS hack

由于不同厂商的浏览器,比如Internet Explorer,Safari,Mozilla Firefox,Chrome等,或者是同一厂商的浏览器的不同版本,如IE6和IE7,对CSS的解析认识不完全一样,因此会导致生成的页面效果不一样,得不到我们所需要的页面效果。CSS hack 就是这种情况下我们针对不同的浏览器去写不同的CSS的一个过程,让它能够同时兼容不同的浏览器,能在不同的浏览器中也能得到我们想要的页面效果。


谈一谈浏览器兼容的思路

  1. 要不要做
  1. 做到什么程度
  1. 如何做

列举几种浏览器兼容的写法

  1. 条件注释 (conditional comment) 是于HTML源码中被IE有条件解释的语句。条件注释可被用来向IE提供及隐藏代码。
<!--[if IE 6]>
    <p>You are using Internet Explorer 6.</p>
    <![endif]-->
    <!--[if !IE]><!-->
    <script>alert(1);</script>
    <!--<![endif]-->
    <!--[if IE 8]>
    <link href="ie8only.css" rel="stylesheet">
    <![endif]-->                                                         <!--IE10不支持条件注释-->
项目 范例 说明
[if !IE] 非IE
lt [if lt IE 5.5] 小于IE 5.5
lte [if lte IE 6] 小于等于IE6
gt [if gt IE 5] 大于 IE5
gte [if gte IE 7] 大于等于IE7
  1. CSS hack
.box{
  color: red;
  _color: blue; /*ie6*/
  *color: pink; /*ie67*/
  color: yellow\9;  /*ie/edge 6-8*/
}

<!–-[if IE 7]>
<link rel="stylesheet" href="ie7.css" type="text/css" />
<![endif]–->

一些与兼容有关的工具
html5shiv.js
respond.js
Modernizr


名词解释


查询属性兼容性的网站caniuse.com

上一篇 下一篇

猜你喜欢

热点阅读