Jump to content

Commented-Out Code For Earlier Browser Versions


Johnny2

Recommended Posts

I'm a bit confused about the "commented-out" code that I'm learning about in the Killersites tutorials.

For instance:

 

 

<!--[if lt IE 9]>

<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>

<![endif]-->

 

 

I think this code is supposed to allow earlier versions of Internet Explorer to display things correctly.

My questions:

 

Are we supposed to leave it commented out???

If so, why?

If so, how does the browser react to it if the browser thinks it is only a comment???

If we are NOT supposed to leave it commented out, why was it commented out in the lessons?

Link to comment
Share on other sites

This is called a conditional comment. What you do is build your site and test with firefox or chrome and then test in IE back to IE 7 should be fine. Then you see what is not working right then rewrite your css in a style sheet for IE. Make sure to link the conditional comment sheet below your main rules in the head.

 

Here is a good article on this http://www.impressivewebs.com/conditional-comments/

Link to comment
Share on other sites

I'm a bit confused about the "commented-out" code that I'm learning about in the Killersites tutorials.

For instance:

 

 

<!--[if lt IE 9]>

<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>

<![endif]-->

 

 

I think this code is supposed to allow earlier versions of Internet Explorer to display things correctly.

My questions:

 

Are we supposed to leave it commented out???

If so, why?

If so, how does the browser react to it if the browser thinks it is only a comment???

If we are NOT supposed to leave it commented out, why was it commented out in the lessons?

Only IE can understand this type of conditional comment and so it knows to execute it if the conditional statement is done correctly just as you have shown in your post. To all other browsers it just a commented out code.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...