HTML condition comments and html comments

Source: Internet
Author: User
Tags html comment

HTML condition comments and html comments

The common HTML comment format is

<! -- Comment -->

IE5 ~ IE9 also supports a specialIf condition comment(It seems a bit similar to the syntax structure during template rendering)

<! -- [If IE]> html statement <! [Endif] -->

In this way, the hack code can be concentrated in one segment when dealing with IE browser compatibility issues, or other unexpected uses

If condition annotations are divided into three forms:

1. Whether it is IE (I .e :!)

<! -- [If IE]> html code <! [Endif] --> <! -- [If! IE]> html code <! [Endif] -->

2. Which version of IE is used (I .e.: =)

<! -- [If IE 6]> html code <! [Endif] --> <! -- [If IE 8]> html code <! [Endif] -->

3. the IE (that is, <, <=,>,> =) of the specified range)

<! -- Browsers earlier than IE8 will execute internal html code. To include IE8, use lte --> <! -- [If lt IE 8]> html code <! [Endif] --> <! -- IE7 or a later version of the browser will execute internal html code. To include IE7, use gte --> <! -- [If gt IE 7]> html code <! [Endif] -->

 

Conditional comments

IE5 ~ The perspective of IE9 is:

The perspective of other browsers is:

If you want the so-called html code IE5 ~ In the if condition comment ~ Although IE9 can recognize but cannot be executed, other browsers can also recognize and execute the code.

<! -- [If! IE]> --> html code <! -- <! [Endif] -->

The idea is to comment out the prefix and suffix of the conditional annotation syntax structure.

IE5 ~ The perspective of IE9 is changed:

The perspective of other browsers becomes:

The middle code can be identified.

I personally think a note when using conditional comments

<!--[if !IE]>--><script src="js/jquery-3.2.1.min.js"></script><!--<![endif]--><!--[if IE]><script src="js/jquery-1.12.4.min.js"></script><![endif]-->

If you can only use one of the top two in each browser, you must remember to consider IE9, because it can also recognize conditional annotations (It seems that IE9 is the transition from IE to modern advanced browsers. CSS3 only supports a part of it, but some problems exists in IE proprietary.)

 

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.