How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?

前端 未结 25 2623
谎友^
谎友^ 2020-11-22 06:19

How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?

I tried this, but

25条回答
  •  旧巷少年郎
    2020-11-22 06:49

    I wouldn't use JavaScript navigator.userAgent or $.browser (which uses navigator.userAgent) since it can be spoofed.

    To target Internet Explorer 9, 10 and 11 (Note: also the latest Chrome):

    @media screen and (min-width:0\0) { 
        /* Enter CSS here */
    }
    

    To target Internet Explorer 10:

    @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
        /* IE10+ CSS here */
    }
    

    To target Edge Browser:

    @supports (-ms-accelerator:true) {
      .selector { property:value; } 
    }
    

    Sources:

    • Moving Internet Explorer specific CSS into @media blocks
    • How to Target Internet Explorer 10 and 11 in CSS
    • CSS Hacks for Windows 10 and Microsoft’s Edge Web Browser

提交回复
热议问题