IE10 conditional IE comments <!--> functionality enabler

When debugging my ASP.NET MVC (Razor-based) web site in IE10, I need to still set IE-specific css. When using IE conditional comments, the following syntax works, when switching IE10 to IE8 Standard rendering mode:

<!--[if IE]><!--> 
<link href="@Url.Content("~/Content/global/global.ie.css")" rel="stylesheet" type="text/css">
<!--<![endif]-->

And this - does not:

<!--[if IE]> 
<link href="@Url.Content("~/Content/global/global.ie.css")" rel="stylesheet" type="text/css">
<![endif]-->

The later syntax is given as an example one on most of the sites that provide info on conditional comments, including the official page on MSDN. What's the difference between these two? Thank you in advance.

Answers


Use "Downlevel-revealed Conditional Comments" to get it working...

Syntax:
<![if IE]>    
     ...statements...  
<![endif]>
Example:
<![if IE]>    
    <link href="@Url.Content("~/Content/global/global.ie.css")" rel="stylesheet" type="text/css">  
<![endif]>

More info:

The downlevel-revealed conditional comment syntax is flagged as invalid HTML by some validation services. Additional characters can be added to construct a valid HTML Comment before and after the HTML content to be revealed.

<!--[if !IE]>--> 
    YOUR HTML 
<!--<![endif]-->

In the example above, the negative conditional expression prevents Internet Explorer from displaying the HTML content within the downlevel-revealed conditional comment block. However, if the conditional expression evaluates to true, the closing "-->" of the first comment appears along with the HTML content in Internet Explorer. To hide these characters from Internet Explorer users, add "

<!--[if !IE]><!--> 
    YOUR HTML 
<!--<![endif]-->

Examples:

Here are some more examples of conditional comments.

<!--[if IE]><p>You are using Internet Explorer.</p><![endif]-->
<![if !IE]><p>You are not using Internet Explorer.</p><![endif]>

<!--[if IE 7]><p>Welcome to Internet Explorer 7!</p><![endif]-->
<!--[if !(IE 7)]><p>You are not using version 7.</p><![endif]-->

<!--[if gte IE 7]><p>You are using IE 7 or greater.</p><![endif]-->
<!--[if (IE 5)]><p>You are using IE 5 (any version).</p><![endif]-->
<!--[if (gte IE 5.5)&(lt IE 7)]><p>You are using IE 5.5 or IE 6.</p><![endif]-->
<!--[if lt IE 5.5]><p>Please upgrade your version of Internet Explorer.</p><![endif]-->

<!--[if true]>You are using an <em>uplevel</em> browser.<![endif]-->
<![if false]>You are using a <em>downlevel</em> browser.<![endif]>

<!--[if true]><![if IE 7]><p>This nested comment is displayed in IE 7.</p><![endif]><![endif]-->

contents taken from Valid HTML for downlevel-revealed conditional comments


Need Your Help

SharePoint 2010 jQuery autocomplete

jquery sharepoint

I'm trying to create a custom field type with jQuery autocomplete functionality. But I'm really stuck now.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.