IE conditional annotation in HTML

Source: Internet
Author: User
Keywords annotation that is equals these
Tags based browser browsers code comment example html html code

ie condition annotation is a special kind of HTML annotation, this annotation only IE5.0 and above version can understand. For example, normal HTML comments are:

<!--this is a comment-->

And only IE can read IE conditional comments are:

<!--[if ie]> <! [endif]-->

Non ie conditional annotation:

<!--[if! ie]>--> Non-ie HTML Code <!--<! [endif]-->

"Non-specific version IE condition annotations" (rarely used):

<!--[if! LT IE 7]><! [ignore[--><![ Ignore[]]>code for browsers that match the IF condition<!--<! [endif]-->

In short, all browsers except "IE on Windows" would consider a conditional annotation to be an ordinary HTML comment. You cannot use conditional annotations in CSS code. IE conditional annotation is very useful for IE to hide or show specific code methods, compared with the _/in the CSS to create bugs, using IE conditional annotation to write css "hacks" is a more reasonable way. Popular point, conditional annotation is some if judgment, but these judgments do not execute in the script, but are executed directly in the HTML code.

The basic structure of a conditional annotation is the same as that of an HTML annotation (<!––>). Browsers other than IE will therefore look at them as normal annotations and ignore them entirely. IE will be based on the if condition to determine whether the same as the parsing of ordinary page content to parse the contents of the conditional comment. Conditional comments Use an HTML annotation structure, so they can only be used in HTML files, not in CSS files.

Syntactically, this is a fairly legitimate generic HTML annotation. Any browser will think that the part between <!– and –> is a comment that ignores it. But IE will also see it [if ie]> to begin interpreting the next code until it encounters <! [EndIf]. Therefore, the following code does not appear in any other browser.

The "comparison operator" allows more flexibility to control the IE version, which is preceded by the "comparison operator" in IE. The legal operators are as follows:

LTE: Is the shorthand for pager than or equal to, meaning less than or equal to. LT: It's a shorthand for pager than, meaning less than. GTE: is the shorthand for greater than or equal to, which is greater than or equal to the meaning. GT: is greater than shorthand, that is, greater than the meaning. : Is not equal to the meaning, and JavaScript is not equal to the same judge character

Example:

<!–[if GT ie 5.5]>/If IE version is greater than 5.5/<!–[if LTE IE 6]>/if IE version is less than or equal to 6/<!–[if! ie]>/If the browser is not IE/

Although it may seem more time-consuming when you first use a conditional annotation, you'll find it handy when you debug your CSS later. Using conditional annotations You just need to write HTML comments, and with bugs you need to write long, ugly code for every rule, and often write hacks to change other hacks. In addition, the conditional annotation is a legitimate HTML annotation for any browser that does not support it. The following are some of the differences between conditional comments and CSS hacks:

Hacks are browser-based bugs that may eventually be fixed. Conditional annotations are based on IE-specific code, and this recognition mechanism is not removed at any time. Every browser can see your hacks, perhaps the next version or a new browser will make mistakes in your hacks code. Only IE can see the conditional annotation, through the additional "IE file" to affect the page, other browsers simply will not download it. Hacks cannot ensure which browsers are in effect and which are not, and the more hacks you use, the more confusing your code will be. Conditional annotations Use version matching to make it easy for authors to write code for a particular version.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.