How do I specify IE 11 specific css file?

旧巷老猫 提交于 2019-12-10 20:42:14

问题


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

<!--[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? Thanks in advance.


回答1:


Use the below hack and followed by your css style:

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




回答2:


Just add below in your CSS stylesheet and see in Internet Explorer 11

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



回答3:


check for if browser is ie11

then directly add link tag from 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



来源:https://stackoverflow.com/questions/28169881/how-do-i-specify-ie-11-specific-css-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!