HTML Conditional Comment

Source: Internet
Author: User

The common form of HTML annotations is

<!-- -

and IE5~IE9 these 5 versions of IE browser also support a special if condition comment (feel a bit like the syntax structure when template rendering)

<!-- [if ie]> HTML statement <! [EndIf]  -

This way, when dealing with IE compatibility issues, you can put the hack code together, or other unexpected uses

If condition comment is divided into three forms

1, whether IE (that is:!)

<!-- [if ie]> HTML code <! [EndIf]  - <!-- [if! Ie]> HTML code <! [EndIf]  -

2, which version of IE (i.e.: =)

<!-- [if IE 6]> HTML code <! [EndIf]  - <!-- [if IE 8]> HTML code <! [EndIf]  -

3, which is the interval of IE (i.e.: <,<=,>,>=)

<!---<!--[if LT IE 8]> html code <![ ENDIF]-<!---<!--[if GT IE 7]> HTML code < ! [EndIf]  -

The above code only IE5~IE9 to recognize the middle of the HTML code, and IE10,IE11 and non-IE will be recognized as a whole comment, they only use the tube "<!--" and "--" on the line, as far as the middle is a bunch of characters.

So if you want the so-called HTML code in the IF condition comment to be recognized but not executable, and other browsers are not recognized but can execute, you can write this IE5~IE9

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

The idea is to comment out the first and last parts of the syntax structure of the conditional annotation, when the IE5~IE9 still recognizes the middle HTML code (the feeling condition annotation is higher than the normal annotation priority level has the wood has ), just before and after each more "--" and "<!--" Insignificant characters, and other browsers also recognize the middle HTML code, just a lot of irrelevant comments.

A point of note for individuals who feel the use of conditional annotations

<!-- [if! Ie]>-<src= "Js/jquery-3.2.1.min.js"></  script><!--<![ ENDIF]-<!--[if Ie]><script src= "Js/jquery-1.12.4.min.js" ></ script><! [EndIf]  -

Is that in all browsers can only use one of the words must remember to consider IE9, because it is also able to recognize the conditional annotation ( feel IE9 is ie to modern advanced browser of the transition, CSS3 only support a part, but before IE proprietary problems still exist )

HTML 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.