【问题标题】:How do I specify IE 11 specific css file?如何指定 IE 11 特定的 css 文件?
【发布时间】:2015-01-27 11:53:44
【问题描述】:

我目前有一个页面,当用户使用以下 html 语法单击打印按钮时,我正在为其应用一些特定于浏览器的 CSS 样式。但是下面的 html 代码不会应用为 IE11(ie11print.css)指定的 css,而是应用为其余 IE 版本(ieprint.css)指定的 css。

<!--[if IE 11]> <link rel="stylesheet" media="print" title="Print" type="text/css" href="/styles/ie11print.css" /><![endif]-->
<!--[if lte IE 10]> <link rel="stylesheet" media="print" title="Print" type="text/css" href="/styles/ieprint.css" /><![endif]-->
<!--[if !IE]>--><link rel="stylesheet" media="print" title="Print" type="text/css" href="/styles/print.css" /><!--<![endif]-->

有人知道如何为 IE11 指定 CSS 文件吗? 提前致谢。

【问题讨论】:

  • 你不应该需要...反正 IE11 不支持条件 cmets。
  • IE 11 与其他浏览器有何不同,您需要包含自定义样式表来修复它?
  • 我使用 zoom:70% 减小了页面大小;对于使用 ieprint.css 文件的所有 IE 版本,它在所有 IE 版本中都能完美运行,但在 IE 11 中,与其他 IE 浏览器相比,它要小得多。我不想在 IE11 中使用缩放。
  • 正如@Paulie_D 提到的,Microsoft 在版本 9 之后删除了条件 cmets。您的 IE10 条件也将不起作用。

标签: html css internet-explorer internet-explorer-11


【解决方案1】:

使用下面的 hack,然后是你的 css 样式:

*::-ms-backdrop,

例子:

*::-ms-backdrop,/*Your element*/ {
       /*Your styles*/
    }

注意:它只会影响IE浏览器。所以你需要在此之前应用你的正常样式。

【讨论】:

    【解决方案2】:

    只需在您的 CSS 样式表中添加以下内容并在 Internet Explorer 11 中查看

    @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) 
     {                                                                                                                     
                 Add your styles here
     }
    

    【讨论】:

    • 谢谢@disha。会试试这个,让你知道
    【解决方案3】:

    检查浏览器是否为ie11

    然后直接从javascript添加链接标签

             window.location.hash = !!window.MSInputMethodContext;
                if (window.location.hash) 
                {
                    var $head = $("head");
                    var $headlinklast = $head.find("link[rel='stylesheet']:last");
                    var linkElement = "<link rel='stylesheet' href='/styles/ie11print.css' type='text/css' media='screen'>";
                    if ($headlinklast.length){
                       $headlinklast.after(linkElement);
                    }
                    else {
                       $head.append(linkElement);
                    }
                }
    

    如果有任何问题,请告诉我。 window.location.hash 将为 ie11 返回 true

    【讨论】:

    • jQuery.browser 在 1.3 版中已弃用,在 1.9 版中已被 删除 (请参阅api.jquery.com/jQuery.browser) - 我也非常怀疑它是否可以检测基于 Internet Explorer 11该版本中用户代理字符串的重大更改以及该方法不受支持的性质。
    • //为 IE11 附加 true,否则为 false window.location.hash = !!window.MSInputMethodContext;您可以使用这种稳健的方法来检测 ie11
    猜你喜欢
    • 2014-06-22
    • 2015-09-25
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 2016-12-31
    • 2015-11-22
    • 1970-01-01
    • 2014-06-07
    相关资源
    最近更新 更多