简体   繁体   English

如何指定IE 11特定的css文件?

[英]How do I specify IE 11 specific css file?

I currently have a page for which I am applying some browser specific CSS styling when user clicks print button using the following html syntax. 我目前有一个页面,当用户使用以下html语法单击打印按钮时,我正在应用某些浏览器特定的CSS样式。 But the following html code wont apply the css specified for IE11(ie11print.css) instead it applies the css that is specified for rest of the IE versions(ieprint.css). 但是下面的html代码不会应用为IE11指定的css(ie11print.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]-->

Does anybody know how to specify a CSS file only for IE11? 有人知道如何仅为IE11指定CSS文件吗? Thanks in advance. 提前致谢。

Use the below hack and followed by your css style: 使用下面的hack,然后是你的css样式:

*::-ms-backdrop,

Example: 例:

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

Note:It will only affects in IE browsers.So You need to apply your normal style before this. 注意:它只会影响IE浏览器。所以你需要在此之前应用你的正常风格。

Just add below in your CSS stylesheet and see in Internet Explorer 11 只需在CSS样式表中添加以下内容,然后在Internet Explorer 11中查看即可

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

check for if browser is ie11 检查浏览器是否为ie11

then directly add link tag from javascript 然后直接从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);
                }
            }

let me know if any concern. 如果有任何疑虑,请告诉我。 window.location.hash will return true for ie11 window.location.hash将为ie11返回true

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

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