Document directory
Original post: IE conditional comments
Author: David Walsh
The most popular Web browser for WD users every day is IE. Microsoft currently has three different versions that account for more than 70% of the domestic desktop browser market share. In particular, Internet Explorer 6 and its domestic browsers, which use it as the kernel, have been violent against domestic users for ten years. In the face of relentless markets, we had to fight with IE for the whole day.
CSS and JavaScript always have such strange problems on IE. For example, the most common problems are double margin, floating and absolute positioning, and PNG is not supported. Fortunately, you can use the target block of HTML to specify which version of IE is or all versions of IE.
Example of IE condition annotation:
<!--[if IE]>
<style type="text/css">
a { color:#fff; }
</style>
<![endif]-->
The above Code sets the color of all links of IE to the 16-bit value of # fff.
<!--[if lt IE 8]>
<script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script>
<![endif]-->
The code above indicates that only the IE browser with IE version earlier than 8 contains the ie8.js library.
<!--[if IE 6]>
<script src="DD_belatedPNG.js"></script>
<script>
DD_belatedPNG.fix('.png');
</script>
<![endif]-->
The code above indicates that the bug of PNG in the IE 6 browser is fixed.
Conditional annotation syntax table
Entries |
Example |
Description |
! |
[If! IE] |
Non-(not) operator. It is directly located in front of the feature, operator, or subexpression to perform Boolean conversion of the expression. |
Lt |
[If lt ie5.5] |
Less than (less-than) operator. If the first real parameter is smaller than the second real parameter, true is returned ). |
LTE |
[If lte ie 6] |
Less than (less-than) or equal to (equal) operator. If the first real parameter is less than or equal to the second real parameter, the return value is true. |
GT |
[If GT ie 5] |
Greater than (greater-than) operator. If the first real parameter is greater than the second real parameter, the return value is true. |
GTE |
[If gte ie 7] |
Greater than (greater-than) or equal to (equal) operator. If the first real parameter is greater than or equal to the second real parameter, the return value is true. |
() |
[If! (Ie 7)] |
Subexpression operator. Concatenates A boolean operator to create a composite expression. |
& |
[If (GT ie 5) & (lt ie 7)] |
And (and) operator. If all the subexpressions are calculated as true, the return value is true. |
| |
[If (ie 6) | (ie 7)] |
Or (OR) operator. If any subexpression is calculated as true, the return value is true. |
When we encounter an IE bug, we can use the perfect method of conditional annotation syntax to quickly solve the problem.
Useful Resources
- Simulate IE7 with IE8
- Msdn documentation Microsoft's "official" Guide
- Conditional comments written by PPK
I wish you a good time coding with IE condition comments!
(End)