以前我们大部分都是用!important来hack,对于ie6和firefox测试可以正常显示,但是ie7以上对!important可以正确解释,会导致页面没按要求显示!搜索了一下,找到了一个针对IE7、IE8不错的hack方式,IE7使用*+html或*line-height: 23px,IE8使用“\9”来区分,比如:line-height: 26px\9。
CSS可以参照如下定义,注意顺序:
- #menu { line-height: 23px; }/* firefox 浏览器实行这句定义 */
- #menu { line-height: 26px\9; }/*ie6,ie7,ie8 这句定义主要尖对IE8来hack*/
- #menu { *line-height: 23px; }/*ie6,ie7 这句定义主要尖对IE7来hack*/
- #menu { _line-height: 23px; }/*ie6 浏览器优先实行这句定义*/
- 或者写成一句
- #menu { line-height:23px; line-height: 26px\9; *line-height: 23px; _line-height:23px; }
- 或者
- * html #menu { line-height: 23px; } /* IE6 浏览器实行这句定义 */
- *+html #menu { line-height: 23px; }/* IE7 浏览器实行这句定义*/
网页里面单独定义IE浏览器
- <!–[if !IE]><!–> 除IE外都可识别 <!–<![endif]–>
- <!–[if IE]> 所有的IE可识别 <![endif]–>
- <!–[if IE 5.0]> 只有IE5.0可以识别 <![endif]–>
- <!–[if IE 5]> 仅IE5.0与IE5.5可以识别 <![endif]–>
- <!–[if gt IE 5.0]> IE5.0以及IE5.0以上版本都可以识别 <![endif]–>
- <!–[if IE 6]> 仅IE6可识别 <![endif]–>
- <!–[if lt IE 6]> IE6以及IE6以下版本可识别 <![endif]–>
- <!–[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]–>