说到浏览器兼容问题,所有前端开发人员肯定都遇到过,这个问题需要面对,也必须得面对。
先说说IE浏览器版本吧,每个版本的IE浏览器有两种模式IE(Q)、IE(S),其中Q代表Quirks mode 怪异模式或混杂模式,这种模式很恶心。另一种是标准模式Standards mode,通常网上见到的很多代码和hack都是针对IE(S)来说的,一旦用户不小心切换到IE(Q),就可能造成意想不到的效果!
我们下面来看一下IE版本的不同hack吧,如下图:
enter image description here
看到网上很多资料写的“_”下划线是IE6特有的hack,不错,在IE6标准模式下面,是的。这样写没有问题。加入页面中IE6和IE7出现同样的问题的时候,我们可以用下划线,说不定IE6调好了,IE7也会跟着好了起来。
经过我实践发现“-”中划线的确是IE6特有的hack,你可以在你的页面中用中划线随便写针对IE6问题的代码,其他浏览器不会出现问题。
IE7特有的hack,一般认为是“*+”,星号和加号一起写。例如 :
aaa{height:25px;-height:30px;+height:31px;} / 普通高度是25像素,IE6是30像素,IE7是31像素 */
还有一种引进css的写法,也可以作为调整网站hack的办法,写法如下:
<!--[if IE 6]>
<link href="ie/ie6.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if IE 9]>
<link href="ie/ie9.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if IE 8]>
<link href="ie/ie8.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if IE 7]>
<link href="ie/ie7.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if IE]>
<link href="ie/ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if lt IE 9]>
<script src="html5_shrrr.js"></script>
<![endif]-->
其他IE的hack就不具体举例子了。
.yy{
background-color: #777777;/*所有识别*/
background-color: #CD2626\9;/*ie6、7、8识别*/
+background-color: #ddd;/*ie6、7识别*/
_background-color: #ddd;/*ie6识别*/
}
由于不同的浏览器对标签的默认样式不同,可以把所有元素都重新设置样式。
body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,from,fieldset,legend,button,input,textarea,th,td{ margin:0; padding:0; }
body,button,input,select,textarea{ font: 12px/ 1.5, arial ,\aaa; }
h1,h2,h3,h4,h5,h6 { font-size : 100%;}
small{ font-size: 12px ;}
button,input,select,textarea { font-size : 100%;}
ul,ol{ list-style:none ;}
a{ text-decroation: none; }
a:hover{ text-decroation: underline; }
sup{ vertical:text-top; }
sub{ vertical: text-bottom; }
fieldset,img{ border:0; }
table{ border-collapse: collapse; border-spacing:0 ;}