IE CSS hack(各种格式错乱)

来源:互联网 发布:大话设计模式php 编辑:程序博客网 时间:2024/04/30 00:24
body {
              background-color:Black;/*火狐+Google*/
              background-color:red\9\0;/*IE9*/
              background-color:blue\0;/*IE8*/
              *background-color:red;/*IE7,IE6*/
              +background-color:navy;/*IE7*/
              _background-color:green;/*IE6*/
}
注意点: IE9  支持  \9\0, 中间不要有空格,写成  background-color:red  \9\0;不会识别。必须 background-color:red\9\0;

            IE8  支持  \0,同样中间不要有空格。

          IE6,IE7 都支持  * ,

            IE6特别支持 下划线_: _background-color:green;

            IE7特别支持加号+: +background-color:green;

        


定义顺序:  火狐Google>IE9>IE8>IE7>IE6;

上面是针对一个 元素的一个css属性。 如果 要整体兼容 一段CSS代码, 就要这么写
/*FireFox,Google浏览器*/
#Menu{
      width:1005px; height:30px;background:red; margin:0px auto;
}
/*IE6浏览器*/
*html #Menu { 
      width:1005px; height:30px;background:navy; margin:0px auto;

/*IE7浏览器*/
*+html #Menu { 
    width:1005px; height:30px;background:gray; margin:0px auto;
}

/*IE7浏览器*/
*:first-child+html #Menu { 
    width:1005px; height:30px;background:gray; margin:0px auto;
}

IE7  的  *+html #Menu 和*:first-child+html #Menu 2种写法,效果一样, 不知道有啥差别,希望网友能给出意见。

注意点: IE6,7都支持*, IE7 特别支持+号。  

当然,如果不一样的css设置 非常多, 可以针对不同浏览器写css样式, 在浏览器的头部 根据不同浏览器来加载css

首先默认加载通用样式
<link rel="stylesheet" type="text/css" href="/style.css" />
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="/ie6.css" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="/ie7.css" />
<![endif]-->

还有其他浏览器,格式如下

<!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]-->
<!--[if IE]> 所有的IE可识别 <![endif]-->
<!--[if IE 6]> 仅IE6 <![endif]-->
<!--[if lt IE 6]> IE6以及IE6以下 <![endif]-->
<!--[if gte IE 6]> IE6以及IE6以上 <![endif]-->
<!--[if IE 7]> 仅IE7 <![endif]-->
<!--[if lt IE 7]> IE7以及IE7以下<![endif]-->
<!--[if gte IE 7]> IE7以及IE7以上 <![endif]-->
<!--[if IE 8]> 仅IE8 <![endif]-->
<!--[if IE 9]> 仅IE9 <![endif]-->
原创粉丝点击