How to define specific CSS rules for IE9 alone?

前端 未结 8 1769
感情败类
感情败类 2020-12-05 00:33

Friends, please help me in defining specific css rule for IE9? For example like this

/* IE 6 fix */
* html .twit-post .delete_note a { background-position-y:         


        
相关标签:
8条回答
  • 2020-12-05 00:53

    \9 is a "CSS hack" specific to Internet Explorer.

    This simply means that the one specific line of CSS ending with a \9;

    In your example, If your CSS looked like this...

    html .twit-post .delete_note a 
    { 
    background-position-y: 2px\9; 
    
    }
    html .twit-post .delete_note a:hover 
    { 
     background-position-y: -14px\9;
     }
    

    The result would be background-position-y: -14px; in IE 9

    0 讨论(0)
  • 2020-12-05 00:55

    I found that in some cases using negative values (when using a compiler to compile LESS files) using:

    margin-right: -15px\9; /* This fails */
    margin-right: ~"-18px\9"; /* This passes */
    
    0 讨论(0)
  • 2020-12-05 01:01

    I think you can do the same as if you want to write specific code for IE6 but say IE9 instead :)

    <!--[if IE 9]>
    Special instructions for IE 9 here
    <![endif]-->
    
    0 讨论(0)
  • 2020-12-05 01:01

    You shouldn't need to target IE9. It is capable of handling modern css and shouldn't be hacked. This is an outdated method of developing.

    0 讨论(0)
  • 2020-12-05 01:02

    You can prepend the CSS style with

    :root
    

    to make it IE9-specific, like this:

    :root #element { color:pink \0/IE9; }  /* IE9 */
    
    0 讨论(0)
  • 2020-12-05 01:06

    Use IE conditional comments:

    <!--[if ie 9]>
        your stuff here
    <![endif]-->
    
    0 讨论(0)
提交回复
热议问题