认识css常见的hack

一、认识css hack

CSS Hack只要是来解决浏览器局部的兼容性问题,主要是因为每个浏览器对css的解析各不相同,导致输出到页面的效果的差异;

二、css hack的三种常见形式:css属性hack,css选择符hack和css针对IE浏览器的条件注释hack

      1、css属性hack:比如IE6能识别"_"和"*",IE7能识别"*"但不能识别"_";

      2、选择符级Hack:IE6能识别*html .class{} IE7能识别*+html .class{}或者*:html .class{};

      3、针对ie的条件注释Hack:比如针对所有IE:针对IE6及以下版本:,此时写在判断力的代码都生效。

三、hack例子

      1、CSS属性级Hack

           color:red; /*所有浏览器*/    _color:red; /*仅IE6*/    *color:red; /*IE6和IE7*/  +color:red; /*仅IE6*/   color:red; /* IE8、IE9 识别*/ color:red9; /* 仅IE9识别 */    color:red!important; /* IE6 不识别!important*/

      2、CSS选择符级Hack

           *html #container { color:red;} /* 仅IE6 识别 */    *+html #container { color:red;} /* 仅IE7 识别 */

      3、IE条件注释Hack

                                 

 

          

     

你可能感兴趣的:(认识css常见的hack)