时很少使用hack,记住的hack也不多。摘记如下,以备后用。
IE:
selector { +property:value; } IE系列可以识别.
selector { *property:value; } IE系列可以识别.
selector { _property:value; } IE系列 (除IE7外) 识别.
* html selector{ property:value; } IE系列 (除IE7外) 可以识别.
html/**/ >body selector { property:value; } IE系列 (除IE7外) 可以识别.
selector { property/**/:value; } 屏蔽IE6用.
selector/**/ { property/**/:value; } 屏蔽IE5和IE6用 (不屏蔽IE5.5) .
select/**/ { property:value; } 屏蔽IE5用.
*+html selector { property:value !important; } 只有IE7可以识别.
IE的if条件Hack
<!–[if IE]> Only IE <![endif]–>
所有的IE可识别
<!–[if IE 5.0]> Only IE 5.0 <![endif]–>
只有IE5.0可以识别
<!–[if gt IE 5.0]> Only IE 5.0+ <![endif]–>
IE5.0包换IE5.5都可以识别
<!–[if lt IE 6]> Only IE 6- <![endif]–>
仅IE6可识别
<!–[if gte IE 6]> Only IE 6/+ <![endif]–>
IE6以及IE6以下的IE5.x都可识别
<!–[if lte IE 7]> Only IE 7/- <![endif]–>
仅IE7可识别
FF:
*:lang(lang) selector { property:value !important; } 用伪类lang(语言)再加上!important进行定义的话,目前只有Firefox可以识别.
Safari:
selector:empty { property:value !important; } 用伪类empty再加上!important进行定义的话,目前只有Safari可以识别.
Opera:
@media all and (min-width: 0px){ selector { property:value; } } 利用特殊继承法进行定义的话,目前只有Opera可以识别.
ie6 ie7 ff 三者的常用区分法
用到的hack法.
— | IE6 | IE7 | FF |
* | √ | √ | × |
!important | × | √ | √ |
_ 或/ | √ | × | × |
所以:
1. 空针对FF; *加!important针对IE7; *针对IE6;
2. 空针对FF; *针对IE7; _针对IE6;
这两种方法都可区别此三种浏览器.
评论