Html <--[如果!IE]>;不起作用

Html <--[如果!IE]>;不起作用,html,internet-explorer,conditional-comments,Html,Internet Explorer,Conditional Comments,我在找工作上有困难 <!--[if !IE]> 当我加上 <!--[if !IE]><!--> <link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css" /> <!--<![endif]--> 由于某种原因,它无法工作。但是如果我加上 <!--[if !IE]><!--> <style>

我在找工作上有困难

<!--[if !IE]>

当我加上

<!--[if !IE]><!-->
<link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css" />
<!--<![endif]-->

由于某种原因,它无法工作。但是如果我加上

<!--[if !IE]><!-->
    <style>
        All my css in here
    </style>
    <!--<![endif]-->

我所有的css都在这里
到实际的html页面(在页眉中),它可以工作。 有什么建议吗? 干杯

更新我的问题

好的,当我离开的时候
我只签入了IE,它正在工作,但现在又回到FF中,no-IE.css也被应用到FF中。因此,我在
中添加了回去,删除了/(并将其添加到主模板中,以便cms不会将其添加回去),所有内容都在FF中工作,但现在样式表正在应用于IE! 所以我试过了

<!--[if IE]>
<link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css">
<![endif]-->


但那没用。 基本上,我试图让这个页面正常工作,但将css移动到样式表中。当然,这必须很简单。我错过了什么?如果不需要的话,我宁愿不使用JQuery。
干杯

首先,正确的语法是:

<!--[if IE 6]>
<link type="text/css" rel="stylesheet" href="/stylesheets/ie6.css" />
<![endif]-->
在这种情况下,您可以更改某些元素的css规则或添加 新css链接参考:


阅读此文:

除IE之外的浏览器将条件语句视为注释,因为它们包含在注释标记中

<!--[if IE]>
Non-IE browsers ignore this
<![endif]-->

但是,当您针对的浏览器不是IE时,您必须使用两条注释,一条在代码之前,一条在代码之后。IE会忽略它们之间的代码,而其他浏览器会将其视为普通代码。因此,针对非IE浏览器的语法为:

<!--[if !IE]-->
IE ignores this
<!--[endif]-->

我忽略了这一点

注意:这些条件注释是。

您需要为
我的完整css块留出一个空间,如下所示,因为IE8对媒体查询很糟糕

<!-- IE 8 or below -->   
<!--[if lt IE 9]>
<link rel="stylesheet" type="text/css"  href="/Resources/css/master1300.css" />        
<![endif]-->
<!-- IE 9 or above -->
<!--[if gte IE 9]>
<link rel="stylesheet" type="text/css" media="(max-width: 100000px) and (min-width:481px)"
    href="/Resources/css/master1300.css" />
<link rel="stylesheet" type="text/css" media="(max-width: 480px)"
    href="/Resources/css/master480.css" />        
<![endif]-->
<!-- Not IE -->
<!-- [if !IE] -->
<link rel="stylesheet" type="text/css" media="(max-width: 100000px) and (min-width:481px)"
    href="/Resources/css/master1300.css" />
<link rel="stylesheet" type="text/css" media="(max-width: 480px)"
    href="/Resources/css/master480.css" />
<!-- [endif] -->



注意:这些条件注释是
.

我使用它,它可以工作:

<!--[if !IE]><!--> if it is not IE <!--<![endif]-->
如果不是IE

Microsoft推荐的下层条件“注释”语法如下:

<![if !IE]>
<link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css" />
<![endif]>


这些不是评论,但它们工作正常。

针对IE用户:

<!--[if IE]>
Place Content here for Users of Internet Explorer.
<![endif]-->
<![if !IE]>
Place Content here for Users of all other Browsers.
<![endif]>

针对所有其他目标:

<!--[if IE]>
Place Content here for Users of Internet Explorer.
<![endif]-->
<![if !IE]>
Place Content here for Users of all other Browsers.
<![endif]>

在此处为所有其他浏览器的用户放置内容。
条件注释只能由Internet Explorer检测,所有其他浏览器都将其作为普通注释进行处理

以IE 6、7等为目标。。在If语句中必须使用“大于等于”或“小于(等于)”。像这样

大于或等于:

<!--[if IE]>
Place Content here for Users of Internet Explorer.
<![endif]-->
<![if !IE]>
Place Content here for Users of all other Browsers.
<![endif]>

小于:

<!--[if IE]>
Place Content here for Users of Internet Explorer.
<![endif]-->
<![if !IE]>
Place Content here for Users of all other Browsers.
<![endif]>


如果有人仍然访问此页面,想知道为什么ie定位不起作用,请更新。IE 10及以后版本不再支持有条件评论。从微软官方网站:

Internet Explorer中已删除对条件注释的支持 10个标准和怪癖模式,用于改进互操作性和 遵守HTML5

有关更多详细信息,请参见此处:

如果您迫切需要以ie为目标,可以使用此jquery代码向添加ie类,然后使用css中的.ie类以ie浏览器为目标

if ($.browser.msie) {
 $("html").addClass("ie");
}
更新:$。浏览器在jQuery 1.9之后不可用。如果您升级到1.9以上的jQuery或已经在使用它,可以在jQuery之后包含jQuery迁移脚本,以便添加缺少的部分:

或者,请检查此线程以了解可能的解决方法:

对于IE浏览器:

<!--[if IE]>
<meta http-equiv="Content-Type" content="text/html; charset=Unicode">
<![endif]-->

对于所有非IE浏览器:

<![if !IE]>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<![endif]>

对于所有大于8的IE浏览器或所有非IE浏览器:

<!--[if (gt IE 8)|!(IE)]><!--><script src="/_JS/library/jquery-2.1.1.min.js"></script><!--<![endif]-->

我发现这段代码可以在我的浏览器上运行:

<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->


注意:HTML5 Shiv和Respond.js IE8支持HTML5元素和媒体查询

条件注释是以

<!-- IE 8 or below -->   
<!--[if lt IE 9]>
<link rel="stylesheet" type="text/css"  href="/Resources/css/master1300.css" />        
<![endif]-->
<!-- IE 9 or above -->
<!--[if gte IE 9]>
<link rel="stylesheet" type="text/css" media="(max-width: 100000px) and (min-width:481px)"
    href="/Resources/css/master1300.css" />
<link rel="stylesheet" type="text/css" media="(max-width: 480px)"
    href="/Resources/css/master480.css" />        
<![endif]-->
<!-- Not IE -->
<!-- [if !IE] -->
<link rel="stylesheet" type="text/css" media="(max-width: 100000px) and (min-width:481px)"
    href="/Resources/css/master1300.css" />
<link rel="stylesheet" type="text/css" media="(max-width: 480px)"
    href="/Resources/css/master480.css" />
<!-- [endif] -->

如果您使用的是IE 10或更高版本,则不再支持条件注释中提到的。
您可以参考另一种方法,也可以从navigator.userAgent检查Trident版本。如果浏览器在兼容模式下工作,这也会得到验证。

我正在使用此javascript检测IE浏览器

if (
    navigator.appVersion.toUpperCase().indexOf("MSIE") != -1 ||
    navigator.appVersion.toUpperCase().indexOf("TRIDENT") != -1 ||
    navigator.appVersion.toUpperCase().indexOf("EDGE") != -1
)
{
    $("#ie-warning").css("display", "block");
}

这对我来说适用于所有版本6以上的浏览器(IE7、8、9、10等,Chrome 3到现在的版本,FF 3到现在的版本):


谢谢你Fernando68,我用了这个:

function isIE () {
     var myNav = navigator.userAgent.toLowerCase();
     return (myNav.indexOf('msie') != -1 || myNav.indexOf('trident') != -1) ? true : false;
}

if(isIE()){
     $.getScript('js/script.min.js', function() {
            alert('Load was performed.');
     });
}

这是在IE9之前的

<!--[if IE ]>
<style> .someclass{
    text-align: center;
    background: #00ADEF;
    color: #fff;
    visibility:hidden;  // in case of hiding
       }
#someotherclass{
    display: block !important;
    visibility:visible; // in case of visible

}
</style>
  @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {enter your CSS here}


您不需要在
之后立即使用
注意:如果IE仅适用于IE9。如果IE消息出现在某些页面上,有些人会留下一些有趣的信息。@cameronjonesweb您可以链接一个参考资料吗?否则这些陈述就没有那么有用了?@trainoasis,我可以,除了我的评论是5年前的之外,请参见上面user1324409的答案以获得更准确的答案。由于jQuery更新,任何使用$.browser.msie的人都必须包含jQuery-migrate.js,然后这就可以了。注意:这些有条件的评论是答案中提供的链接。这很好。谢谢你。样式表可以工作,但是我现在的问题是,在页面顶部标题上方,它出现在ie中(标记出现在标题区域而不是正文中)-1:这个答案是不正确的,因为
ie忽略了这一点
不会对ie隐藏!(7、8或9)没有一个答案对我有效,也许在最近发布的IE10(也在IE9模式下试用)中有所改变所有的尝试最终都到达了终点!所有浏览器(IE和非IE)上的IE部分。IE10不支持条件语句。请注意-中的空格不应存在任何空格(例如介于!--和之间)[.它不适用于空格。谢谢你的评论,但如果我使用,那么其他浏览器也会应用它。这不是重点,让其他浏览器应用该部分吗?-1:这里提到的
!IE
技术实际上会执行IE 7到10的注释块。注意:这些条件注释自ne 2013,这是唯一正确的答案
  @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {enter your CSS here}