有条件的评论 [英] Conditional Comments

查看:106
本文介绍了有条件的评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是UI的新手.我看到了用于识别IE浏览器的条件注释,例如

I am a newbie to UI. I see the conditional comments used to identify the IE browser like

<!--[if IE 10]> <html class="no-js ie10" lang="en"> <![endif]-->
<!--[if !IE]><!--> <html lang="en" class="no-js"> <!--<![endif]-->

它们工作正常,但是谁能解释它如何工作? IE不会将这些陈述视为注释吗?

They work fine but can anyone explain how it works? Doesn't IE recognize these statements as comments?

推荐答案

首先,IE10没有条件注释识别,它已被禁用,仅适用于IE9及更低版本.超过10的版本比以前的版本少很多错误. 这是这样的:

First of all, IE10 does not have Conditional Comments Recognition, it has been disabled, it works only for IE9 and lower. Versions over 10 are much less buggy than the earlier ones. This is how this works:

<!--[if lte IE8]>
  <style type="text/css">
    IE lower or equal to 8 CSS rules go here
  </style>
<![endif]-->

整个样式表

<!--[if lte IE8]>
  <link rel="stylesheet" type="text/css" href="ie8-and-lower.css"/>
<![endif]-->

降低并等于IE7

<!--[if lte IE7]>

低于IE7

<!--[if lt IE7]>

大于IE7

<!--[if gt IE7]>

不是IE7

<!--[if !IE7]>

IE7

<!--[if IE7]>

条件注释在样式表中不起作用.但是,您可以在HTML中使用条件注释,以将不同的CSS类或ID应用于随后可以使用CSS定位的元素.

Conditional comments do not work within stylesheets. But, you can use conditional comments in your HTML to apply different CSS classes or IDs to elements that you can then target with CSS.

工作如下:

<!--[if IE7]>
  <div id="content" class="ie7">
<![endif]-->
<!--[if !IE7]>
  <div id="content">
<![endif]-->

这篇关于有条件的评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆