有时候咱们在制做网页的时候,会遇到不一样浏览器,对填充和边距显示的不一样效果。致使心情纳闷
如今提供解决这个困扰的方法!
对FF、Opear等支持Web标准的浏览器与比较顽固的IE浏览器进行针对性的CSS hack
/*FF、Opear等支持Web标准的浏览器*/
#header {
margin-top: 23px;
margin-bottom: 23px;
}
/*IE6浏览器*/
*html #header {
margin-top: 13px;
margin-bottom: 13px;
}
/*IE7浏览器*/
*+html #header {
margin-top: 18px;
margin-bottom: 18px;
}
所以,当你在遇到这种状况的时候能够用
* html 来定义IE6
*+html 来定义IE7
更新:
还有一种css hack直接与其余浏览器一块儿写在一条css表达式中
#header{
margin-top: 13px; /* 全部浏览器都支持 */
margin-top: 13px !important; /* Firefox、IE7支持 */
_margin-top: 13px; /* IE6支持 */
*margin-top: 13px; /* IE六、IE7支持 */
+margin-top: 13px; /* IE7支持 */
margin-top: 13px\9; /* IE六、IE七、IE八、IE9支持 */
margin-top: 13px\0; /* IE八、IE9支持 */
}
须要注意书写顺序:全部浏览器、Firefox、IE八、IE七、IE6依次排列。css