首页 > Web开发 > 详细

认识css常见的hack

时间:2018-09-30 11:56:54      阅读:154      评论:0      收藏:0      [点我收藏+]

一、认识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:<!–[if IE]><!–您的代码–><![endif]–>针对IE6及以下版本:<!–[if lt IE 7]><!–您的代码–><![endif]–>,此时写在判断力的代码都生效。

三、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

          <!--[if IE]>此处内容只有IE可见<![endif]-->    <!--[if IE 6]>此处内容只有IE6.0可见<![endif]-->    <!--[if IE 7]>此处内容只有IE7.0可见<![endif]-->   <!--[if gt IE 6]> IE6以上版本可识别,IE6无法识别 <![endif]-->    <!--[if gte IE 7]> IE7以及IE7以上版本可识别 <![endif]--> <!--[if lt IE 7]> 低于IE7的版本才能识别,IE7无法识别。 <![endif]-->    <!--[if lte IE 7]> IE7以及IE7以下版本可识别<![endif]-->   <!--[if !IE]>此处内容只有非IE可见<![endif]-->

 

          

     

认识css常见的hack

原文:https://www.cnblogs.com/tangjianqiang/p/9728617.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!