how to write IE 8 specific css styles

2019-08-07 03:39发布

Is it possible to write IE 8 specific styles for few elements without using js or jquery? I have a requirement in which line-height is used , this works fine firefox and chrome where as in IE8 i want to reduce 2 px of line-height can i do this in style class ?

3条回答
SAY GOODBYE
2楼-- · 2019-08-07 04:06

Use this inside of head tag:

<!--[if IE 8]>
<link rel="stylesheet" href="ie8.css" />
<![endif]-->
查看更多
闹够了就滚
3楼-- · 2019-08-07 04:09

Yes, you can use Paul-Irish's way of targetting IE Browsers:

<!--[if lt IE 7]>  <html class="ie ie6 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 7]>     <html class="ie ie7 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 8]>     <html class="ie ie8 lte9 lte8"> <![endif]-->
<!--[if IE 9]>     <html class="ie ie9 lte9"> <![endif]-->
<!--[if gt IE 9]>  <html> <![endif]-->
<!--[if !IE]><!--> <html>             <!--<![endif]-->

Or the new one:

<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->

So for just targetting IE 8, you can use:

<!--[if IE 8 ]>    <html class="ie8"> <![endif]-->
查看更多
做自己的国王
4楼-- · 2019-08-07 04:15

Css conditional comments will help you do this

<!--[if IE 8]>
IE 8 stuff here
<![endif]-->

Have a look at http://www.quirksmode.org/css/condcom.html for more info.

查看更多
登录 后发表回答