CSS hack 汇总

时间:2021-09-27 07:21:00

1, IE条件注释法,微软官方推荐的hack方式。

<!--[if gte IE 6]> IE6以及IE6以上版本可识别 <![endif]-->
<!--[if IE 7]> 仅IE7可识别 <![endif]-->
<!--[if lt IE 7]> IE7以及IE7以下版本可识别 <![endif]-->
<!--[if gte IE 7]> IE7以及IE7以上版本可识别 <![endif]-->

 

只在IE下生效
<!--[if IE]>
这段文字只在IE浏览器上显示
<![endif]-->

只在IE6下生效

<!--[if IE 6]>
这段文字只在IE6浏览器上显示
<![endif]-->

只在IE6以上版本生效

<!--[if gt IE 6]>
这段文字只在IE6以上版本IE浏览器上显示
<![endif]-->

只在IE7上不生效

<!--[if ! IE 7]>
这段文字在非IE7浏览器上显示
<![endif]-->

非IE浏览器生效

<!--[if !IE]><!-->
这段文字只在非IE浏览器上显示
<!--<![endif]-->

 

读此文css hack 汇总,突然想起来,好久没有写css了,都快把hack的方式給忘了,重新回顾一下:

_  只对ie6生效

*  只对ie6, ie7生效

  • “\9″  只在IE6/IE7/IE8/IE9/IE10下生效
  • “\0”  只在 IE8/IE9/IE10下生效
  • “\9\0”只在IE9/IE10下生效
  • 目前如果需要只针对ie8的hack,可先使用在IE8/IE9/IE10生效的“\0”,再用仅在IE9/IE10生效的“\9\0”hack覆盖之前的样式。

selector{
  color:#F00\0;  /* only for IE8&IE9&IE10 */
  color:#000\9\0; /* only for IE9&IE10 */
}

---------------------------------------------------------------------

CSS Hack

  1. _          IE6
2. * IE6/7
3. !important IE7/Firefox
4. *+ IE7
5. \9 IE6/7/8
6. \0 IE8
7. 条件hack
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"><![endif]--> IE7以下版本
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8"><![endif]--> IE7
<!--[if IE 8]> <html class="no-js lt-ie9"><![endif]--> IE8
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]--> IE8以上

<转载自:http://blog.csdn.net/liuxiaoyue909/article/details/8471422 & http://lfsp.btwlo.com/cssHack.html>