简体   繁体   English

如何为IE10专门添加CSS Hack?

[英]How to add CSS Hack specifically for IE10?

I am trying to add css only for iE 10. 我想为iE 10添加css。

Actually my css is working fine in chrome and firefox. 实际上我的css在chrome和firefox中运行良好。 But is creating some problem in IE 10. 但是在IE 10中造成了一些问题。

I tried this code and made ie10.css but it is not working. 我尝试了这个代码,并制作了ie10.css,但它无法正常工作。

<script> 
if (/*@cc_on!@*/false) { 

    var headHTML = document.getElementsByTagName('head')[0].innerHTML; 

headHTML    += '<link type="text/css" rel="stylesheet" href="css/ie10.css">'; 
document.getElementsByTagName('head')[0].innerHTML = headHTML; 
} 
</script>

It is not working. 它不起作用。 Kindly help. 请帮助。

You can easily track the latest versions of IE (mostly IE 10 and IE 11) using 您可以使用轻松跟踪IE的最新版本(主要是IE 10和IE 11)

1. CSS media query hack: 1. CSS媒体查询hack:

/* 
    #ie10,11 will only be red in MSIE 10, 
    both in high contrast (display setting) and default mode 
*/

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { 
   //-- Put your IE specific css class here 
}

OR 要么

@media screen and (min-width:0\0) {  
    /* IE9 and IE10 rule sets go here */  
}

Read this 读这个

Working Example 工作实例

2. Browser Detection: 2.浏览器检测:

if ($.browser.msie && $.browser.version == 10) {
  $("html").addClass("ie10");
}

3. Using script (NOT Tested): 3.使用脚本(未测试):

<script>
    /*@cc_on
      @if (@_jscript_version == 10)
          document.write('<link type= "text/css" rel="stylesheet" href="your-ie10-styles.css" />');
      @end
    @*/
</script >

Note : I know document.write is considered bad practice. 注意:我知道document.write被认为是不好的做法。

Conditional comments (ie10 dropped conditional comments): 条件评论(即10条条款评论):

if you want to load external css file for IE, you can use conditional comments . 如果要为IE加载外部css文件,可以使用条件注释 But as you mentioned in question you wants for IE 10 and ie10 dropped conditional comments. 但正如你提到的那样,你想要IE 10和ie10删除条件评论。

microsoft drop conditional comments in ie10 . 微软在ie10中删除条件评论

Here is the another tricks which I used in my project, you can replace h1 with your class or own CSS 这是我在项目中使用的另一个技巧,你可以用你的类或自己的CSS替换h1

IE10 Only 仅限IE10

http://css-tricks.com/ie-10-specific-styles/ http://css-tricks.com/ie-10-specific-styles/

Use this JavaScript: 使用此JavaScript:

var doc = document.documentElement;
doc.setAttribute('data-useragent', navigator.userAgent);

Then use this CSS: 然后使用这个CSS:

html[data-useragent*='MSIE 10.0'] h1 { color: blue; }

Click here for all earlier version for IE 单击此处查看IE的所有早期版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM