<! – >不起作用

我遇到了麻烦

<!--[if !IE]> 

上class。 我想知道是否因为我在文档中有这个

 <!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]--> 

当我添加

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

到我的头由于某种原因,它不起作用。 但是,如果我添加

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

到实际的HTML页面(在标题)它的作品。 有什么build议么? 干杯

更新我的问题

好的,当我删除<!-->我只检查在工作的IE浏览器,但现在回到FF,no-ie.css也被应用于FF。 所以我加回到<!-->并删除了/(并将其添加到主模板中,所以cms不会将它添加回来),并且所有的工作都在FF中进行,但现在样式表正在被应用到IE ! 所以我试了

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

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

这没有用。 基本上我试图让这个页面工作http://css-tricks.com/examples/ResponsiveTables/responsive.php,但将CSS移入样式表。 当然这很简单。 我错过了什么? 我宁愿不使用JQuery,如果我不必。 干杯

 <!--[if !IE]><!--><script src="zepto.min.js"></script><!--<![endif]--> <!--[if IE]><script src="jquery-1.7.2.min.js"></script><![endif]--> 

注意: 从IE 10开始不再支持这些条件注释。

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

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

但是,如果您的目标浏览器不是IE浏览器,则必须使用2条评论,一条是前一条,另一条是代码。 IE会忽略它们之间的代码,而其他浏览器会把它当作普通的代码。 针对非IE浏览器的语法是:

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

注意: 从IE 10开始不再支持这些条件注释。

一个更新,如果有人仍然到达这个网页,想知道为什么ie定位不工作。 IE 10及以后版本不再支持条件注释。 来自MS官方网站:

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

请参阅这里了解更多详细信息: http : //msdn.microsoft.com/en-us/library/ie/hh801214(v=vs.85).aspx

如果你迫切需要目标即,你可以使用这个jQuery代码添加一个ie类,然后在你的css中使用.ie类目标即浏览器。

 if ($.browser.msie) { $("html").addClass("ie"); } 

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

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

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

 <!--[if !IE]><!--> if it is not IE <!--<![endif]--> 

微软推荐的低级语法 – 显示有条件的“评论”是这样的:

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

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

你需要为<!-- [if !IE] -->放置一个空格<!-- [if !IE] -->我的完整的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] --> 

针对IE用户:

 <!--[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 gte IE 7]> Place Content here for Users of Internet Explorer 7 or above. <![endif]--> 

小于:

 <!--[if lt IE 6]> Place Content here for Users of Internet Explorer 5 or lower. <![endif]--> 

资料来源:mediacollege.com

首先正确的语法是:

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

试试这个post: http : //www.quirksmode.org/css/condcom.html和http://css-tricks.com/how-to-create-an-ie-only-stylesheet/

另一件你可以做的事情是:

用jQuery检查浏览器:

 if($.browser.msie){ // do something... } 

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

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

对于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]> 

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

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

条件注释是一个以<!--[if IE]>开头的注释, <!--[if IE]>浏览器以外的任何浏览器都无法读取该注释。

从2011年开始,微软公布了IE 10的条件注释,不支持https://msdn.microsoft.com/en-us/library/hh801214(v=vs.85).aspx

使用条件注释的唯一select是请求IE将您的站点作为支持条件注释的IE 9运行。

你可以编写你自己的CSS和/或JS文件,只有其他浏览器不会加载或执行它。

此代码片段显示如何使IE 10或11运行ie-only.css和ie-only.js其中包含自定义代码来解决IE兼容性问题。

  <html> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9"> <!--[if IE]> <meta http-equiv="Content-Type" content="text/html; charset=Unicode"> <link rel="stylesheet" type="text/css" href='/css/ie-only.css' /> <script src="/js/ie-only.js"></script> <![endif]--> </html> 

这适用于所有浏览器(比如IE7,8,9,10等,Chrome3直到现在,FF3直到现在)。

 //test if running in IE or not function isIE () { var myNav = navigator.userAgent.toLowerCase(); return (myNav.indexOf('msie') != -1 || myNav.indexOf('trident') != -1) ? true : false; } 

如果您使用的是IE 10或更高版本,请参阅http://tanalin.com/en/articles/ie-version-js/中提到的条件注释。; 您可以参考https://gist.github.com/jasongaylord/5733469作为替代方法,也可以从navigator.userAgent中检查Trident版本。; 这也validation了浏览器在兼容模式下工作的情况。

我正在使用此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"); } 

谢谢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.'); }); } 

我得到这个代码在我的浏览器上工作:

 <!--[if lt IE 9]> <script src="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元素和媒体查询