Details IE condition annotation

Source: Internet
Author: User
Tags comments

Overview

If you get tired of it. For low version IE write smelly and long hack,ie condition annotation will be a more graceful solution. Of course, the function of the conditional annotation is more than just those features, in addition to evading the disgusting hack, it can also be used for different IE versions (Ie5.5-9,ie10 do not support conditional annotations) to make different corresponding, such as for different IE load different styles, or scripts and so on, More functions await our discovery and application.

Introduction to Conditional comments

The conditional annotation (Conditional comments) in IE has excellent distinguishing ability between IE and IE non ie, which is a common hack method in Web design.
Conditional comments can only be used for IE5 or above, IE10 not supported above.
If you have more than one IE installed, the conditional annotation will be standard with the highest version of IE.
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 comment syntax

Project Example Description
! [If! IE] The NOT operator. This is placed immediately in front of the feature, operator, or subexpression to reverse the Boolean meaning of the Expre Ssion.
The NOT operator. This is the pendulum immediately in front of the function, operator, or subexpression to reverse the meaning of the Boolean expression.
Lt [If Lt IE 5.5] The Less-than operator. Returns true if the argument is less than the second argument.
is less than the operator. Returns true if the first argument is less than the second argument.
Lte [If LTE IE 6] The Less-than or equal operator. Returns true if the argument is less than or equal to the second argument.
is less than or equal to the operation. Returns true if the first argument is less than or equal to the second argument.
Gt [If GT IE 5] The Greater-than operator. Returns true if the argument is greater than the second argument.
is greater than the operator. Returns true if the first argument is greater than the second argument.
Gte [If GTE IE 7] The Greater-than or equal operator. Returns true if the argument is greater than or equal to the second argument.
is greater than or equal to the operation. Returns true if the first argument is greater than or equal to the second argument.
( ) [If! (IE 7)] subexpression operators. Used in conjunction with a Boolean operators to create more complex expressions.
Child expression Operators. Used with Boolean operators to create more complex expressions.
& [If (GT IE 5) & (LT IE 7)] The AND operator. Returns true if all subexpressions evaluate to True
And operator. Returns true if all the subexpression evaluates to True
| [If (IE 6) | (IE 7)] The OR operator. Returns true if any of the subexpressions evaluates to True.
Or operator. Returns True if the subexpression evaluates to True.

Examples of usage methods for conditional comments

<!–[if IE 5]> only IE5.5 visible <! [endif]–>
<!–[if gt ie 5.5]> only IE 5.5 visible <! [endif]–>
<!–[if LT ie 5.5]> is visible only under IE 5.5 <! [endif]–>
<!–[if GTE IE 5.5]>ie 5.5 and above visible <! [endif]–>
<!–[if LTE IE 5.5]>ie 5.5 and below visible <! [endif]–>
<!–[if! ie 5.5]> is not IE 5.5 ie visible <! [endif]–>

Conditional annotation Use case

Special tips:

1. Someone will try to use <!--[if! Ie]> to define conditions in non-IE browsers, but note that conditional annotations can only be performed under IE, and that this code is ignored as annotations in non-ie browsing.

2, we usually use the IE condition annotation according to the browser different load different CSS, thus solves the style compatibility problem. In fact, it can do more. It can protect any code block--html code block, JavaScript code block, server-side code ... Look at the code below.

The code is as follows:


&lt;!--[if ie]&gt;


&lt;script type= "Text/javascript" &gt;


alert ("You are using IE browser!") ");


&lt;/script&gt;


&lt;! [endif]--&gt;
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.