How to specify a css property that will only be applied if the browser is IE in the stylesheet?

I know, in order to include a browser specific css file, you can do the following

<!--[if IE]> 
    <link rel="stylesheet" type="text/css" href="style.css" />
<!-->

But is there a way to do this in the stylesheet itself?

EDIT

Thanks for the answers, I'm just going to create a new IE stylesheet and override what I need. I think this is the best way to do something.

+3
source share
5 answers

, , IF . , , ( - ).

<!--[if IE]> 
    <link rel="stylesheet" type="text/css" href="StyleIE.css" />
<!-->
+2

, .

, _ , div {width: 200px; _width: 100px;} 200 , ie, 100px IE.

+2

...

.foo{
  border:1px solid #000;
  *border:3px dotted #00f;/*IE6 & IE7 Only*/
  _border:2px dashed #f00;/*IE6 Only*/
}

, :

  • W3C (Firefox, Safari, Opera ..)
    • 1px
  • IE7
    • 3px
  • IE6
    • 2px

( ) (), ( )

+1
source

You can also use the flag! important for this, but it can have unintended side effects.

Press me i'm important

0
source

Source: https://habr.com/ru/post/1712953/


All Articles