CSS兼容IE6 IE7 IE8 IE9 Firefox的总结

时间:2023-03-08 17:32:35
CSS兼容IE6 IE7 IE8 IE9 Firefox的总结
<!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;
}*/ /* 二:其他说明
1、如果你的页面对IE7兼容没有问题,又不想大量修改现有代码,同时又能在IE8中正常使用,微软声称,
开发商仅需要在目前兼容IE7的网站上添加一行代码即可解决问题,此代码如下:
<meta http-equiv="x-ua-compatible" content="ie=7" />
2、body:nth-of-type(1) 如果这样写,表示全局查找body,将会对应第一个<body>。
3、还有其他写法,比如:
*html #test{}或者 *+html #test{}
4、*+html 对IE7的hack 必须保证HTML顶部有如下声明:
http://www.w3.org/TR/html4/loose.dtd
5、顺序:Firefox、IE8、IE7、IE6依次排列。
小知识:什么是CSS hack?
   由于不同的浏览器,比如IE6、IE7、IE8、Firefox等,对CSS的解析认识不一样,因此会导致生成的页面效果不一样,得不到我们所需要的页面效果。
   这个时候我们就需要针对不同的浏览器去写不同的CSS,让它能够同时兼容不同的浏览器,能在不同的浏览器中也能得到我们想要的页面效果。
   这个针对不同的浏览器写不同的CSS code的过程,就叫CSS hack,也叫写CSS hack。*/ </style>
</head>
<body>
<div id="div1">
</div>
</body>
</html>