兼容IE6/IE7/IE8/FireFox的css hack
.color{background-color: #CC00FF;background-color: #FF0000\9;*background-color: #0066FF;_background-color: #009933;}**记住上面得样式解释为顺序是 ff、ie8、ie7、ie6 **
显示的结果:
用火狐浏览,颜色是紫色
用 IE8 浏览,颜色是红色
用 IE7 浏览,颜色是蓝色
用 IE6 浏览,颜色是绿色
如果你只是为了兼容ie7和8,其实可以在<head>里加上这样一条代码:
<meta http-equiv="X-UA-Compatible" content="IE=7">
即可免去你大量修改代码,但是我发现,有些后台程序员往往会把它删掉,具体原因我也不清楚。
例子:
<!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>无标题文档</title><style type="text/css">.main{width:200px;color:#fff;height:400px;background:#f00;height:200px\9;background:#ff0\9;*height:200px;*background:#0ff;_height:100px;_background:#000;}</style></head><body><div class="main">ff红色height:400px / IE8黄色height:200px / IE7 蓝色height:200px / IE6黑色height:100px</div></body></html>
-----------------------------------------------------------------------------------------------------------------------------------
微软在IE8提供三种解析页面的模式
IE8 Standard Modes :默认的最标准的模式,严格按照W3C相关规定
IE7 Standards Modes :IE7现在用的解析网页的模式,开起机关是在<head>中加入 <meta http-equiv="X-UA-Compatible" content="IE=7">
Quirks Modes :IE5用的解析网页的模式,开起机关是删除HTML顶部的DOCTYPE声明
注意:不同模式间的网页在IE8中可以互相 frame ,因此因不会模式下的DOM和CSS渲染不一样,所以会引发很多问题,务必注意如果你的页面对IE7兼容没有问题,又不想大量修改现有代码,同时又能在IE8中正常使用,微软声称,开发商仅需要在目前兼容IE7的网站上添加一行代码即可解决问题,此代码如下:
<meta http-equiv="x-ua-compatible" content="ie=7" />
IE8 最新css hack:
"\9" 例:"margin:0px auto\9;".这里的"\9"可以区别所有IE和FireFox.
"*" IE6、IE7可以识别.IE8、FireFox不能.
"_" IE6可以识别"_",IE7、IE8、FireFox不能.
----------------------------------------------------------------------------------------------------------------------------------
一些IE6 IE7 IE8 FF的CSS hack
p{+color:#f00;} 支持 IE6 IE7 不支持FF IE8p{_color:#f00;} 支持 IE6 不支持FFp{color:#00f !important;}p{color:#f00;} 支持 IE7 IE6 FF IE8p{color:#00f !important;color:#f00;} 支持 IE7 IE8 FF 不支持 IE6head:first-child+body p{color:#f00;} 支持 IE7 IE8 FF 不支持 IE6
支持 IE8 不支持IE6 IE7 FF
html*p{color:#f00;} 支持 IE6 IE7 不支持FF IE8html>p{color:#f00;} 支持 IE7 IE8 FF 不支持 IE6html p{color:#f00;} 支持 IE7 IE8 FF 不支持 IE6@import 'style.css';@import "style.css";@import url(style.css); @import url('style.css');@import url("style.css"); 支持 IE7 IE6 FF IE8p{color:#f00;} 支持 IE6 IE7 FF 不支持 IE8* html p {color:#f00;} 支持 IE6 不支持FF IE7 IE8*+html p {color:#f00;} 支持 IE7 IE8 不支持FF IE6p {*color:#f00;} 支持 IE7 IE6 不支持FF IE8
====================================================
这样写,也许会简单些,很方便,但是这个只是IE8对IE7的兼容模式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><meta http-equiv="x-ua-compatible" content="ie=7"><html xmlns="http://www.w3.org/1999/xhtml">
注意:<meta http-equiv="x-ua-compatible" content="ie=7"> IE8兼容IE7的模式
页:
[1]