IE conditional statement ie hack Encyclopedia _ other comprehensive

Source: Internet
Author: User
Tags comment tag comments html comment
Conditional comments work as follows:
Copy Code code as follows:

<!--[if IE 6]>special instructions for IE 6 here<! [endif]-->
[Code]

Their basic structure is the same as a HTML comment (<!---->). Therefore all other browsers would you them as normal comments and would ignore them.
IE, though, has been programmed to recognize the special <!--[if ie]> syntax, resolves the ifand parses the content of the conditional comment as if it were normal page content.
Since conditional comments Use of the HTML comment structure, they can only is included in HTML files, and not in CSS files. I ' d have preferred to put the special styles into the CSS file, but that ' s impossible. can also put a entire new <link> tag in the conditional comment referring to a extra style sheet.
Example
Below I added a lot of conditional comments that print out messages according to your IE version.

Note However, this if you use multiple explorers on one computer, the conditional comments would render as if all of these EXP Lorer versions are the highest Explorer version available on your machine (usually Explorer 6.0).

Test
Below are a few conditional comments that reveal the IE version of you ' re using.

According to the conditional comment this is IE
According to the conditional comment this is IE 7
According to the conditional comment it is IE lower than 9
According to the conditional comment it is IE lower or equal to 7
According to the conditional comment it is IE greater than 6

Code
The syntax I use is:
[Code]
<p class= "Accent" >
<!--[If ie]>
According to the conditional comment it is ie<br/>
<! [endif]-->
<!--[if IE 6]>
According to the conditional comment it is IE 6<br/>
<! [endif]-->
<!--[if IE 7]>
According to the conditional comment it is IE 7<br/>
<! [endif]-->
<!--[if IE 8]>
According to the conditional comment it is IE 8<br/>
<! [endif]-->
<!--[if IE 9]>
According to the conditional comment it is IE 9<br/>
<! [endif]-->
<!--[if GTE IE 8]>
According to the conditional comment this is IE 8 or higher<br/>
<! [endif]-->
<!--[If Lt IE 9]>
According to the conditional comment it is IE lower than 9<br/>
<! [endif]-->
<!--[If LTE IE 7]>
According to the conditional comment it is IE lower or equal to 7<br/>
<! [endif]-->
<!--[if GT IE 6]>
According to the conditional comment it is IE greater than 6<br/>
<! [endif]-->
<!--[if! Ie]>-->
According to the conditional comment this is not ie<br/>
<!--<! [endif]-->
</p>

Note the special syntax:

Gt:greater than
Lte:less than or equal to
Also note to the last one. It has a different syntax, and its contents are shown to all browsers that is are not IE:
Copy Code code as follows:

<!--[if! Ie]>-->


CSS hack?
Are conditional comments CSS hacks? Strictly speaking, yes, since they can serve to give special style instructions to some browsers. However, they do is rely on one browser bug to solve another one, as all true CSS hacks do. Besides, they can be used to more than CSS hacks only (though that rarely happens).

Since conditional comments are not based on a browser hack but on a deliberate feature I believe they the safe to use. Sure, other browsers could implement conditional comments, too (though as yet none have do), but they ' re unlikely to React to the specific query <!--[if Ie]>.

I use conditional comments, though sparingly. The I can find the real CSS solution to a Explorer Windows problem. If I can ' t, though, I don ' t hesitate to use them.

Comment tag
A reader told me IE also supports the (non-standard) <comment> tag.

<p>this is <comment>not</comment> ie.</p>

This isie.

This tag might is a replacement for the! IE conditional comment.

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.