针对主流浏览器的CSS-HACK写法及IE常用条件注释

一、通用区分方式:


IE6、IE7能识别*,标准浏览器(如FF)不能识别*;
IE6能识别*,但不能识别 !important;
IE7能识别*,也能识别 !important;
IE8能识别\0,不能识别*,+,_,* 加!important;
FF不能识别*,但能识别 !important;
例如style=”*width:10px!important; width:20px;”,其在IE7下宽度为10px,在IE6下宽度是20px.


其中还有如下三种写法:


第一种

width:100px; /* FireFox及其他浏览器 * /
width:200px\0; /* IE8能识别\0*
/
*width:300px!important; /* ,IE7 既能能识别*号,也能识别important *
/
*width:400px; /* IE6也能识别*号 *
/
/*提示:请注意书写顺序*/
 

第二种

width:100px; /* FireFox及其他浏览器 * /
width:200px\0; /* IE8能识别\0*
/
*width:300px; /* IE7也能识别*号 *
/
_width:400px; /* IE6能识别下划线*
/
/*提示:请注意书写顺序*/
 

第三种

width:100px; /* FireFox及其他浏览器 * /
width:200px\0; /* IE8能识别\0*
/
+width:300px; /* +只识别IE7 *
/
_width:400px; /* IE6能识别下划线*
/
/*提示:请注意书写顺序*/
 

二、不常见的HACK(OP表示Opera,SA表示Safari),其中第3条比较实用


1..color1{ color:#F00; color/*\**/:#00F /*\**/}/*IE6,IE7,IE8,FF,OP,SA识别*/
2..color2{ color:#F00; color /*\**/:#00F /*\9**/}/*IE7,IE8,FF,OP,SA识别*/
3..color3{ color:#F00; color/*\**/:#00F \9}/*IE6,IE7,IE8识别*/
4..color4{ color:#F00; color /*\**/:#00F\9}/*IE7,IE8识别*//*“color”和“/*\**/”之间有个空格*/


三、各种浏览器独立支持的hack


width:100px\0;/* 支持IE8 */
_width:100px; /* 支持IE6 */
[width:100px; /* 支持IE6,7 */
+width:100px; /* 支持IE6,7 */
*width:100px; /* 支持IE6,7 */
*width:100px!important; /* 支持IE6,7, */
*+width:100px; /* 支持IE6,7, */
*+width:100px!important;/* 支持IE6,7, */
width:100px\9; /* 支持IE6,7,8 */
width:100px!important; /* 支持IE6,7,8,FF */
w\idth:100px; /*IE5.x不支持 IE6、IE7、IE8、FF支持 */

 

四、IE特有的html条件注释使用规则


 

 Example Source Code
<!--[if IE 7]> 
<style type="text/css"> 
</style>
<![endif]-->
 <!--[if IE 6]> 
<style type="text/css">
</style> 
<![endif]-->

 

1.仅IE可见的写法

<!--[if IE]>此处内容只有IE可见<![endif]-->
 

2.仅IE6可见的写法

<!--[if IE 6]>此处内容只有IE6.0可见<![endif]-->
 

3.仅IE7可见的写法

<!--[if IE 7]>此处内容只有IE7.0可见<![endif]-->
 

4.版本区间可显示写法

<!--[if lt IE 6]>IE6以及IE6以下版本可识别<![endif]-->
<!--[if gte IE 6]>IE6以及IE6以上版本可识别<![endif]-->
<!--[if lt IE 7]>IE7以及IE7以下版本可识别<![endif]-->
<!--[if gte IE 7]>IE7以及IE7以上版本可识别<![endif]-->
PS:区间注释代码实际用起来貌似不包括本区间,这里需要注意下
 

5.非IE可见的写法(注意:此条不符合WEB标准,但的确实用

<!--[if !IE]>此处内容只非IE可见<![endif]-->
 

PS1:IE8降级为IE7:<meta http-equiv="X-UA-Compatible" content="IE=7">

PS2:解决chrome不支持12号以下字体的代码:-webkit-text-size-adjust:none;

PS3:li左侧ico样式:li { list-style:disc outside none; }

 
EX SP:
.box   
{   
    color: black;                              /* ff */  
    color: #fff\9\0;                            /* IE9 */  
    color: #ff0000\0;                       /* IE8 */  
    [color: #666; color: #999;       /* Safari Chrome */  
    *color: green;                           /* IE7 */  
    _color: blue;                             /* IE6 */  
}  
@media all and (min-width: 0px){
/* Safari与Opera浏览器的共同样式 */
 }
@media all and (-webkit-min-device-pixel-ratio:0){
 /* 这里单独设置Safari的样式 */
}
 HTML代码
<div class="box">  
这里根据设置不同浏览器的CSS HACK显示不同的颜色!   
</div>  
在IE6浏览器中字体颜色为蓝色;
在IE7浏览器中字体颜色为绿色;
在IE8浏览器中字体颜色为红色;
在IE9浏览器中字体颜色为白色;
在Firefox浏览器中字体颜色为黑色;
在safari、Chrome浏览器中字体颜色为灰色。

<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
第一个 强制使用机器上最新版的IE
第二个 360默认的浏览器内核会优先使用极速内核

转载于:https://www.cnblogs.com/mixzo/p/4213379.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值