<! - [if!IE]>不工作

use*_*788 137 html internet-explorer conditional-comments

我遇到了麻烦

<!--[if !IE]>
Run Code Online (Sandbox Code Playgroud)

上班.我想知道是不是因为我的文件中有这个

<!doctype html>
<!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
<!--[if IE 7]>    <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="">
<!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)

当我添加

<!--[if !IE]><!-->
<link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css" />
<!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)

由于某种原因,我的标题不起作用.但是,如果我添加

<!--[if !IE]><!-->
    <style>
        All my css in here
    </style>
    <!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)

到实际的html页面(在标题中)它的工作原理.有什么建议?干杯

更新我的问题

好吧,当我删除时, <!-->我只检查了IE工作,但现在回到FF中,no-ie.css也已应用于FF.所以我添加回来<!-->并删除了/(并将其添加到主模板中,因此cms不会将其添加回来)并且所有都在FF中工作但现在样式表正在应用于IE!所以我试过了

<!--[if IE]>
<link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css">
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

<!--[if !IE]> -->
<link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css">
<!-- <![endif]-->
Run Code Online (Sandbox Code Playgroud)

那没用.基本上我正试图让这个页面工作http://css-tricks.com/examples/ResponsiveTables/responsive.php但是将css移动到样式表中.当然,它必须简单.我错过了什么?如果我不需要,我宁愿不使用JQuery.干杯

Thi*_*80s 231

<!--[if !IE]><!--><script src="zepto.min.js"></script><!--<![endif]-->
<!--[if IE]><script src="jquery-1.7.2.min.js"></script><![endif]-->
Run Code Online (Sandbox Code Playgroud)

注意:IE 10以后不再支持这些条件注释.

  • @Giedrius从IE10开始,不再支持条件评论**:http://msdn.microsoft.com/en-us/library/ie/hh801214(v = vs.85).aspx (48认同)
  • 截至2013年6月,这是此页面上*唯一*正确答案. (39认同)
  • 它在IE 11中不起作用,它加载脚本,即使条件是!IE (8认同)
  • 这条线缺少右尖括号吗?不应该是:&lt;!-[if!IE]&gt; &lt;!-&gt; &lt;script src =“ zepto.min.js”&gt; &lt;/ script&gt; &lt;!-&gt; &lt;![endif]-&gt; (2认同)

小智 66

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

<!--[if IE]>
Non-IE browsers ignore this
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

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

<!--[if !IE]-->
IE ignores this
<!--[endif]-->
Run Code Online (Sandbox Code Playgroud)

注意:IE 10以后不再支持这些条件注释.

  • -1:这个答案是*不正确*因为`<! - [if!IE] - > IE忽略了这个<! - [endif] - >`****不是**隐藏在IE中!(7,8或9) (19认同)
  • 这些答案都没有对我有用,也许在最近的IE10版本中也有所改变(在IE9模式中也尝试过). - 所有尝试最终都到达所有浏览器的IE部分(IE而不是IE). (3认同)
  • IE10不支持条件语句. (2认同)

Sel*_*lay 37

如果有人仍然到达此页面的更新,想知道为什么ie目标不起作用.IE 10及以后版本不再支持条件评论.来自MS官方网站:

Internet Explorer 10标准和怪癖模式中已删除对条件注释的支持,以提高互操作性并符合HTML5.

有关详细信息,请参阅此处:http://msdn.microsoft.com/en-us/library/ie/hh801214(v = vs.85).aspx

如果您迫切需要定位ie,您可以使用此jquery代码添加ie类,然后在您的css中使用.ie类来定位即浏览器.

if ($.browser.msie) {
 $("html").addClass("ie");
}
Run Code Online (Sandbox Code Playgroud)

更新:$ .browser在jQuery 1.9之后不可用.如果你升级到1.9以上的jQuery或者你已经使用它,你可以在jQuery之后包含jQuery迁移脚本,这样它就会添加缺少的部分: jQuery Migrate Plugin

或者,请检查此线程以获取可能的解决方法:更新到jQuery 1.9.1后出现browser.msie错误

  • 请注意,这是自jQuery 1.3以来已弃用并在1.9中删除 (2认同)

小智 13

我使用它,它的工作原理:

<!--[if !IE]><!--> if it is not IE <!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)

  • 注意:[从IE 10开始不再支持这些条件注释](https://msdn.microsoft.com/library/hh801214(v = vs.85).aspx) (2认同)

小智 12

微软推荐的下层显示条件"注释"的语法是这样的:

<![if !IE]>
<link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css" />
<![endif]>
Run Code Online (Sandbox Code Playgroud)

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

  • 注意:[从IE 10开始不再支持这些条件注释](https://msdn.microsoft.com/library/hh801214(v = vs.85).aspx) (2认同)

Bor*_*isD 9

首先,正确的语法是:

<!--[if IE 6]>
<link type="text/css" rel="stylesheet" href="/stylesheets/ie6.css" />
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

试试这篇文章:http: //www.quirksmode.org/css/condcom.htmlhttp://css-tricks.com/how-to-create-an-ie-only-stylesheet/

你可以做的另一件事:

使用jQuery检查浏览器:

if($.browser.msie){ // do something... }
Run Code Online (Sandbox Code Playgroud)

在这种情况下,您可以更改某些元素的css规则或添加新的css链接引用:

阅读本文:http://rickardnilsson.net/post/2008/08/02/Applying-stylesheets-dynamically-with-jQuery.aspx

  • 由于jQuery更新,任何使用$ .browser.msie的人都必须包含jquery-migrate.js,然后这将有效. (2认同)

Joh*_*ord 8

您需要为<!-- [if !IE] --> My full 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] -->
Run Code Online (Sandbox Code Playgroud)

  • 是不是这一点,让其他浏览器应用该部分? (3认同)
  • -1:这里提到的`!IE`技术实际上会执行IE 7到10的注释块。 (2认同)

Mun*_*ies 8

对于IE用户的定位:

<!--[if IE]>
Place Content here for Users of Internet Explorer.
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

针对所有其他人:

<![if !IE]>
Place Content here for Users of all other Browsers.
<![endif]>
Run Code Online (Sandbox Code Playgroud)

条件注释只能由Internet Explorer检测,所有其他浏览器都将其作为正常注释进行处理.

目标IE 6,7等.你必须在If语句中使用"大于等于"或"小于(等于)".像这样.

大于或等于:

<!--[if gte IE 7]>
Place Content here for Users of Internet Explorer 7 or above.
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

小于:

<!--[if lt IE 6]>
Place Content here for Users of Internet Explorer 5 or lower.
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

资料来源:mediacollege.com

  • 注意:[从IE 10开始不再支持这些条件注释](https://msdn.microsoft.com/library/hh801214(v = vs.85).aspx) (2认同)

Chi*_*kid 7

这是为了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>
Run Code Online (Sandbox Code Playgroud)

这是针对IE9之后的

  @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {enter your CSS here}
Run Code Online (Sandbox Code Playgroud)


Kap*_*pil 5

对于IE浏览器:

<!--[if IE]>
<meta http-equiv="Content-Type" content="text/html; charset=Unicode">
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

对于所有非IE浏览器:

<![if !IE]>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<![endif]>
Run Code Online (Sandbox Code Playgroud)

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

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