3

How to hack css Inline style only on IE ?

to hack css Inline style only on IE in all version, How can i do ?

Like that

<div style = "
               color: #eee;
               border: 1px solid #000;
for ie only // line-height : 32px;     
             "/>
user3215821
  • 263
  • 2
  • 4
  • 11
  • This question is duplicated http://stackoverflow.com/questions/4750088/css-display-inline-block-issue-with-ie – Vinicius Monteiro Jan 20 '14 at 16:12
  • @ViniciusMonteiro thats IE6/7 only – JochemQuery Jan 20 '14 at 16:15
  • When asking questions like this, please always specify the IE version(s) that you need it to work for. Also, please elaborate on what the problem is in IE that you're trying to fix; there might be an alternative solution that doesn't require IE hacks. – Spudley Jan 20 '14 at 16:18
  • @JochemQuery This question covers all versions of IE, I tested to make sure. – Vinicius Monteiro Jan 20 '14 at 16:22
  • Here is an extensive list of css hacks you can use both inline and in separate stylesheet http://abbasharoon.me/css-hacks-internet-explorer/ – Metabolic Nov 10 '14 at 00:44

3 Answers3

5

You need to add * before the property name, and that will target only IE7, so you need to write this line-height : 32px; as *line-height : 32px;

As I realized you wanted hacks for each IE, so here you go

  • For IE6 - _
  • For IE7 - *
  • For IE8 - \0
  • For IE9 - \9

Declare styles for IE10 specifically using CSS Only

@media all and (-ms-high-contrast: none) { 
   /* This won't go inline but can be used at document level*/
   /* Declaration Blocks Goes Here*/
}

You can read here for more information on how to declare IE only styles using @media queries


Still I would suggest you to use conditional comments which will make your life much easier instead of declaring inline styles.

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
0
<!--[if IE]>
    div.classname{
        line-height: 32px; //ie only 
    }
<![endif]-->

Source: http://css-tricks.com/how-to-create-an-ie-only-stylesheet/

Edit:

  • Give that div a class
  • Give that class a specific ie style.
JochemQuery
  • 1,495
  • 2
  • 26
  • 38
0
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
   #myElement {
        /* Enter your style code */
   }
}
dxpkumar
  • 371
  • 2
  • 9