Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commented out HTML

In my _Layout.cshtml file I have the following lines

<!--[if IE 7]>
  <link rel="stylesheet" type="text/css" media="all" href="/Content/css/ie7.css" />
<![endif]-->    
<!--[if IE 6]>
  <link rel="stylesheet" type="text/css" media="all" href="/Content/css/ie6.css" />
<![endif]-->

Both these lines are commented out. I've always wondered, but was too afraid to ask if commented out code like this is needed or not. In other words if I am using IE6 or IE7 will the appropriate line above become 'activated' somehow or does the simple fact that it is commented out mean that it will never get called?

like image 464
Sachin Kainth Avatar asked Dec 01 '22 23:12

Sachin Kainth


2 Answers

These are conditional comments.

As far as HTML is concerned, they are commented out.

Internet Explorer violates the standard to ignore the comments under certain conditions (i.e. when they start with a [unless you are some version of ie] string) so it will "activate" the code inside.

like image 178
Quentin Avatar answered Dec 10 '22 13:12

Quentin


This is called browser specific conditional comments. It will choose, the stylesheet specified in the first line if you use IE 7 and the style sheet specified in the second line if you use the IE 6

like image 32
Tino M Thomas Avatar answered Dec 10 '22 11:12

Tino M Thomas