如何添加CSS Hack专门为IE10? [英] How to add CSS Hack specifically for IE10?

查看:185
本文介绍了如何添加CSS Hack专门为IE10?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为iE 10添加css。



实际上我的css在chrome和firefox中工作正常。但是在IE 10中创建了一些问题。



我试过这个代码,并使ie10.css,但它不工作。

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

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

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

它不工作。

解决方案

您可以使用

轻松跟踪最新版本的IE(主要是IE 10和IE 11)

1。 CSS媒体查询hack:

  / * 
#ie10,11只会在MSIE 10 ,
在高对比度(显示设置)和默认模式下
* /

@media屏幕和(-ms-高对比度:活动) -contrast:none){
// - 将您特定于IE的css类放在这里
}

OR

  @media屏幕和(min-width:0 \0){
/ * IE9和IE10规则集到这里* /
}

阅读此



工作示例



2。浏览器检测

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

3。使用指令码(未测试):

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

注意:我知道 document.write <

条件注释(ie10删除条件注释)

如果要为IE加载外部css文件,可以使用条件注释。但是正如你提到的,你想要IE 10和 ie10删除条件注释。



ie10中的微软投放条件评论


I am trying to add css only for iE 10.

Actually my css is working fine in chrome and firefox. But is creating some problem in IE 10.

I tried this code and made ie10.css but it is not working.

<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

1. CSS media query 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:

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

3. Using script (NOT Tested):

<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.

Conditional comments (ie10 dropped conditional comments):

if you want to load external css file for IE, you can use conditional comments. But as you mentioned in question you wants for IE 10 and ie10 dropped conditional comments.

microsoft drop conditional comments in ie10.

这篇关于如何添加CSS Hack专门为IE10?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆