CSS Hack是什么?ie6,7,8的hack分别是什么

CSS Hack是一种针对不同浏览器(如Internet Explorer、Firefox、Opera等)的CSS样式特殊写法,通过使用不同的CSS语法或者使用特定条件的判断语句,让CSS代码能够针对不同的浏览器进行差异化渲染,从而达到兼容的目的。

对于Internet Explorer 6、7、8,CSS Hack主要有以下几种写法:

条件注释法

<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="ie8.css">
<![endif]-->

在上面的代码中,通过条件注释法,针对不同的IE版本加载不同的CSS样式表文件。

属性选择器法

对于IE6,可以使用属性选择器法来写Hack,例如:

*+html .selector {color: red;} /* IE6 */

对于IE7,可以使用以下代码:

css*:first-child+html .selector {color: red;} /* IE7 */

对于IE8,可以使用以下代码:

css*+html .selector {color: red;} /* IE8 */

针对盒模型的Hack写法

针对IE6的盒模型Hack写法如下:

.selector {width: 100px; padding: 0 10px; _width: 90px; _padding: 0;} /* IE6 */

针对IE7的盒模型Hack写法如下:

.selector {width: 100px; padding: 0 10px; zoom:1;} /* IE7 */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值