ie条件注释_IE条件注释

ie条件注释

Internet Explorer

As we all know too well, Internet Explorer is the browser that tends to cause web developers the most pain. Maybe it's because Microsoft currently has 3 very different browser versions we have to account for. Maybe it's because the earlier versions of the browsers didn't adhere to standards. Maybe it's because IE6 wasn't updated for so many years. Whatever the reason, IE is here and we have to deal with it.

众所周知,Internet Explorer是导致Web开发人员最痛苦的浏览器。 也许是因为Microsoft当前必须考虑3个非常不同的浏览器版本。 可能是因为早期版本的浏览器不符合标准。 也许是因为IE6这么多年没有更新。 不管是什么原因,IE都在这里,我们必须处理它。

CSS and JavaScript issues within each version of IE present us with layout and functionality issues. Double margins, floating and absolute positioning, and lack of PNG support are probably the most frequent problems. Luckily Internet Explorer has been supporting conditional comments which allow us to target blocks of HTML toward all IE browsers or specified IE browsers.

IE的每个版本中CSS和JavaScript问题都向我们提出了布局和功能问题。 双重利润,浮动和绝对定位以及缺乏PNG支持可能是最常见的问题。 幸运的是,Internet Explorer一直支持条件注释,这使我们能够将HTML块定向到所有IE浏览器或指定的IE浏览器。

IE条件注释的示例 (Examples of IE Conditional Comments)


<!--[if IE]>
<style type="text/css">
a		{ color:#fff; }
</style>
<![endif]-->


The example above sets the color of links to red if the browser is any flavor of Internet Explorer.

如果浏览器是Internet Explorer的任意一种,则上面的示例将链接的颜色设置为红色。


<!--[if lt IE 8]>
<script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script>
<![endif]-->


The example above example includes the IE8.js library int the page if the version of Internet Explorer is less than 8.

如果Internet Explorer的版本小于8,则上面的示例将IE8.js库包含在页面中。


<!--[if IE 6]>
<script src="DD_belatedPNG.js"></script>
<script>
  DD_belatedPNG.fix('.png');
</script>
<![endif]-->


The example above fixes PNGs if the browser is Internet Explorer 6.

如果浏览器是Internet Explorer 6,则上面的示例修复了PNG。

条件注释语法表 (Conditional Comments Syntax Table)

ItemExampleComment
![if !IE]The NOT operator. This is placed immediately in front of the feature, operator, 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.
项目 评论
[如果!IE] NOT运算符。 它直接放置在featureoperator子表达式的前面,以反转表达式的布尔含义。
lt [如果是IE 5.5] 小于运算符。 如果第一个参数小于第二个参数,则返回true。
[如果是IE 6, 小于或等于运算符。 如果第一个参数小于或等于第二个参数,则返回true。
gt [如果> IE 5] 大于运算符。 如果第一个参数大于第二个参数,则返回true。
te [如果是gte IE 7] 大于或等于运算符。 如果第一个参数大于或等于第二个参数,则返回true。
() [如果!(IE 7)] 子表达式运算符。 与布尔运算符结合使用以创建更复杂的表达式。
[如果(gt IE 5)&(lt IE 7)] AND运算符。 如果所有子表达式的计算结果为true,则返回true
| [如果(IE 6)|(IE 7)] OR运算符。 如果任何子表达式的计算结果为true,则返回true。

While we all dislike Internet Explorer's bugs, their conditional comment syntax provides us a perfect method for fixing them quickly.

尽管我们都不喜欢Internet Explorer的错误,但它们的条件注释语法为我们提供了一种快速修复它们的理想方法。

宝贵的资源 (Valuable Resources)

  • If you'd like to cut one of the browser version issues out of the equation, you can always make IE8 emulate IE7.

    如果您想排除其中一种浏览器版本问题,则始终可以使IE8模拟IE7

  • Be sure to check out the MSDN documentation for Microsoft's "official" guide.

    请务必查看Microsoft的“官方”指南的MSDN文档

  • PPK has some awesome notes about conditional comments.

    PPK关于条件注释有一些很棒的注释。

Have fun fixing your code in Internet Explorer with conditional comments!

有趣的是使用条件注释在Internet Explorer中修复代码!

翻译自: https://davidwalsh.name/ie-conditional-comments

ie条件注释

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值