CSS HACK 整理

HACK1 #example {

margin:5px!important/* for Firefox */

margin:10px/* for IE6 */

margin /**/:11px/* for IE5 */

}

*+
html #example{margin:15px!important; }/* for IE7 */

说明:!important声明可以提升指定样式规则的应用优先权。上面“for Firefox” 有“!important”,“for IE7” 也要加“!important”,否则实际出来后IE7依然使用第一个maring值5px。
HACK2 #example {margin:5px; }/* for Firefox */

html #example {margin:10px;} /* for IE6 */

*+html #abc{margin:15px!important;} /* for IE7 */

说明:“for IE7”要加“!important”,“+html”能被ie7与ie5.01所识别,但ie5.01不识别important,所以*+html 再加!important 才只能被ie7识别。
HACK3 #example {

margin:5px/* For Firefox */

*margin:10px/* For IE7 & IE6*/

_margin:15px/* For IE6*/

}

说明:这样写css文件无法通过验证,但是代码可以写的比较少。
HACK4:使用IE专用的条件注释 <!--其他浏览器 -->

<
link rel="stylesheet" type="text/css" href="css.css" />

<!--[if 
IE 7]>

<!-- 
适合于IE7 -->

<
link rel="stylesheet" type="text/css" href="ie7.css" />

<![endif]-->

<!--[if 
lte IE 6]>

<!-- 
适合于IE6及以下 -->

<
link rel="stylesheet" type="text/css" href="ie.css" />

<![endif]-->

说明:条件注释的语法:
[*]gt /Greater than/大于/<!--[if gt IE 5.5]>
[*]gte /Greater than or equal to/大于等于/<!--[if gte IE 5.5]>
[*]lt /Less than/小于/<!--[if lt IE 5.5]>
[*]lte /Less than or equal to/小于等于/<!--[if lte IE 5.5]>
[*]! /Note/不等于/<!--[if !IE 5.5]>        
HACK5 example{

margin5px;/*FF*/

>margin10px;/*IE5*/

}

example/*IE5.5 */{

>
/*IE only*/margin15px;/*IE6*/

>/*IE only*/margin /*IE5.5*/20px;

}

说明:“margin”定义的顺序不能改变,即FF-IE5-IE6-IE5.5。对于IE的定义在属性前要加“>”,因为“example/**/{}”这个HACK在FF中可以识别。

Tags: css

上一篇: 放弃一直使用的天网开始使用风云防火墙
下一篇: 关于商业计划书

相关文章

访客评论

  1. #1 冬天来了 2007, June 8, 3:31 PM
    其实网页标准更应该去统一一下浏览器,不然最累的还是搞网站的
  2. #2 silverys 2007, June 11, 4:32 PM
    我上司要求在IE5.0&5.5,IE6.0,IE7.0,firfox2.0,Opera浏览器,苹果机上的safari浏览器,都可以正常显示。
    而且要通过验证。
    整个网站的页面又多,大哥你说着怎么办啊。
  3. #3 kairyou 2007, June 12, 12:58 PM
    css HACK 能解决的,你用各种浏览器测试下就能知道啦。

发表评论

评论内容 (必填):