Jump to content

keeping "<!--[if lte IE 7]>" statements


htmlnewbie23
 Share

Recommended Posts

I am using some css menu examples from Stu Nichols website to both learn css and modify them for my site.A number of Stu's example menus contain statements like:<!--[if lte IE 7]><style type="text/css">#menu ul {display:inline;}</style><![endif]-->Are these just informative "comments" I can safely delete or are they part of the needed css code?(I posted the question on his forum but did not get an answer).Thank you.

Link to comment
Share on other sites

These are Internet Explorer Conditional Statements. Since they are nested in comment blocks, they are ignored by other browsers. IE recognizes the syntax, however, and uses them.Stu has recognized that IE versions 7 and earlier must use a slightly different style to achieve the same effect that works everywhere else. So this creates a style sheet only for those browsers. lte means "less than or equal to." Better leave this code exactly where it is.Make sense?

Edited by Deirdre's Dad
Link to comment
Share on other sites

That said, I think too many developers use these as a crutch, because they have not discovered the techniques that work in all browsers (perhaps with a little tweaking for IE). I do use them occasionally, and I think Stu's usage is probably on the mark. But when I see them all over a document, I know I'm seeing the work of a lazy or overworked developer.

Link to comment
Share on other sites

No - you have to use "hacks" - pieces of code interpreted incorrectly by certain browsers due to deficiencies in their implementations - instead.

Link to comment
Share on other sites

Hacks don't necessarily have to be syntactically malformed - for example, there is a bug in IE7 which makes it consider comments as child elements, and so will apply styles in a :first-child selector to that comment, instead of the actual first-child.

<style type="text/css">	body div { background-color:blue; }	body :first-child { background-color:red; }</style><body>	<!-- this is a comment to trick IE7 -->	<div><p>The background will be blue in IE7, else red.</p></div></body>

Conditional comments are comments.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...