区别IE8浏览器的CSS hack

上次我们介绍了ie6、ie7、火狐(firefox)浏览器的css hack区别方法及运用,接下来我们介绍微软最新IE成员ie8与前面浏览器的css hack写法区别。在使用css hack中我们运用了CSS读取原理。同时安装ie6、ie7、ie8浏览器方法:IETester浏览器测试工具介绍。

CSS hack区分如下——注意顺序与浏览器CSS HACK位置:
CSS hack:区分IE6,IE7 ,IE8,firefox
区别不同浏览器,CSS hack写法:
区别FF与IE6:
background:orange;*background:blue; 解释:FF只能识别background:orange; IE6识别*background:blue;
区别IE7与IE6:
background:green !important;background:blue;或者*background:green;_background:blue;
区别IE6与IE8:
background:orange; /*/background:blue;/**/
区别IE7与IE8:
background:orange; /*/background:blue;/**/
区别FF与IE7:
background:orange; *background:green !important;
区别FF,IE7,IE8,IE6
background:orange;*background:green important;background:#1119;_background:blue;
或者使用
区别FF,IE7,IE8,IE6
background:orange;*background:green !important;background:#1119;*background:blue;

CSS Hack实例例子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>DIV+CSS各浏览器css hack测试,www.divcss5.com测试</title>
<style type="text/css">
<!--
.STYLE1 { font-size:18px;color:#FF0000;*color:#00FF00 !important;color:#0000FF 9;*color:#FFFF00;}
.STYLE2,.STYLE3,.STYLE4,.STYLE5{ font-size:14px;}
.STYLE2 {color: #FFFF00}
.STYLE3 {color: #FF0000}
.STYLE4 {color: #00FF00}
.STYLE5 {color: #0000FF}
-->
</style>
</head>
<body>
<span class="STYLE1">我是测试颜色,不在不同浏览器下显示颜色不同哦!-<a href="http://www.divcss5.com/">DIV+CSS</a></span><br />

<span class="STYLE2">我是颜色在IE6显示</span> <br />
<span class="STYLE4">我是颜色在ie7显示</span> <br />
<span class="STYLE5">我是颜色在ie8显示</span> <br />
<span class="STYLE3">我是颜色在火狐(firefox)显示</span>
</body>
</html>

在线演示-点击这里
以上代码你拷贝到一个新建的html文件在不同版本浏览器测试就会有不同效果。运用此例子即可解决我们在日常DIV+CSS开发时候的css hack问题。

同时我们如果不想那么的麻烦来做IE8的css hack,我们只需要在html的<head></head>之间加入<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />,最好加到CSS文件下发即可,在IE8 下和IE7下显示内容相同,这样我们只需区分IE6、IE7、火狐(firefox)的css hack即可。很多大型站点都采用在head加入此代码来减少css bug。

浏览过此页用户还浏览以下内容:
CSS hack之区别不同浏览器的写法
CSS3_CSS3.0介绍