<!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> <title>无标题页</title> <!--CSS兼容IE6 IE7 IE8 IE9 Firefox的总结--> <style type="text/css"> #div { /* 一:*各类浏览器css hack兼容状况*/ width:200px; height:200px; background: red; /* 全部浏览器*/ /* background: black!important; /* 有ie7,ie8,ie9,,firefox,chrome支持 */ /* _background: yellow; /* 只有ie6支持 */ /* +background:yellow; /* 只有ie6,ie7支持 */ /* *+background:yellow; /* 只有ie6,ie7支持 */ /* *background:black; /* 只有ie6,ie7支持 */ /* background:yellow\9; /* 有ie6,ie7,ie8,ie9支持 */ /* background:black\0; /* 有ie8,ie9支持 */ } /* body:nth-of-type(1) div /* 有ie9,firefox,chrome,Safari支持 */ /*{ width: 200px; height: 200px; background: red; }*/ /* 二:其余说明 一、若是你的页面对IE7兼容没有问题,又不想大量修改现有代码,同时又能在IE8中正常使用,微软声称, 开发商仅须要在目前兼容IE7的网站上添加一行代码便可解决问题,此代码以下: <meta http-equiv="x-ua-compatible" content="ie=7" /> 二、body:nth-of-type(1) 若是这样写,表示全局查找body,将会对应第一个<body>。 三、还有其余写法,好比: *html #test{}或者 *+html #test{} 四、*+html 对IE7的hack 必须保证HTML顶部有以下声明: http://www.w3.org/TR/html4/loose.dtd 五、顺序:Firefox、IE八、IE七、IE6依次排列。 小知识:什么是CSS hack? 因为不一样的浏览器,好比IE六、IE七、IE八、Firefox等,对CSS的解析认识不同,所以会致使生成的页面效果不同,得不到咱们所须要的页面效果。 这个时候咱们就须要针对不一样的浏览器去写不一样的CSS,让它可以同时兼容不一样的浏览器,能在不一样的浏览器中也能获得咱们想要的页面效果。 这个针对不一样的浏览器写不一样的CSS code的过程,就叫CSS hack,也叫写CSS hack。*/ </style> </head> <body> <div id="div1"> </div> </body> </html>