Tuesday, August 30, 2011

Html Conditional Comments for Internet Explorer

  
Conditional comments are used to detect special versions of browsers. Browser detection is used for browser compatibility and correct rendering. Here are some helpful tables for using "Html Comments";

Comment syntax table:

Comment typeSyntax or possible value
standard HTML comment<!-- Comment content  -->
downlevel-hidden<!--[if expression]> HTML <![endif]-->
downlevel-revealed<![if expression]> HTML <![endif]>

Supported features table:

ItemExampleComment
IE[if IE]The string "IE" is a feature corresponding to the version of Internet Explorer used to view the Web page.
value[if IE 7]An integer or floating point numeral corresponding to the version of the browser. Returns a Boolean value of true if the version number matches the browser version.
WindowsEdition[if WindowsEdition]Internet Explorer 8 on Windows 7. The string "WindowsEdition" is a feature corresponding to the edition of Windows used to view the Web page.
value[if WindowsEdition 1]An integer corresponding to the edition of Windows used to view the Web page. Returns a Boolean value of true if the value matches the edition being used. 
true[if true]Always evaluates to true.
false[if false]Always evaluates to false.


Operators table:

ItemExampleComment
![if !IE]The NOT operator. This is placed immediately in front of the featureoperator, or subexpression to reverse the Boolean meaning of the expression.
lt[if lt IE 5.5]The less-than 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 first argument is less than or equal to the second argument.
gt[if gt IE 5]The greater-than 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 first argument is greater than or equal to the second argument.
( )[if !(IE 7)]Subexpression operators. Used in conjunction 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
|[if (IE 6)|(IE 7)]The OR operator. Returns true if any of the subexpressions evaluates to true.

Here is an example;
<!--[if IE 9]>
<p>Welcome to Internet Explorer 9.</p>
<![endif]-->

For more information, See: http://msdn.microsoft.com/en-us/library/ms537512.aspx


See Also:

1 comment:

  1. HTML codes that is a nice blog checkout my blog at
    http://definingwords.blogspot.com/2012/08/romantic-words.html
    feel free to leave a comment

    ReplyDelete