• CSS引用条件表达式[摘抄文档]


    [Conditional comments only work in Explorer on Windows, and are thus excellently suited to give special instructions meant only for Explorer on Windows. They are supported from Explorer 5 onwards, and it is even possible to distinguish between 5.0, 5.5 and 6.0.]

    1. Their basic structure is the same as an HTML comment (<!-- -->). Therefore all other browsers will see them as normal comments and will ignore them entirely.
    2. Explorer Windows, though, has been programmed to recognize the special <!--[if IE]> syntax, resolves the if and parses the content of the conditional comment as if it were normal page content.
    3. Since conditional comments use the HTML comment structure, they can only be included in HTML files, and not in CSS files. I'd have preferred to put the special styles in the CSS file, but that's impossible. You can also put an entire new <link> tag in the conditional comment referring to an extra style sheet.

    Code:

    The syntax I use is:

    <p><!--[if IE]>
    According to the conditional comment this is Internet Explorer<br />
    <![endif]-->
    <!--[if IE 5]>
    According to the conditional comment this is Internet Explorer 5<br />
    <![endif]-->
    <!--[if IE 5.0]>
    According to the conditional comment this is Internet Explorer 5.0<br />
    <![endif]-->
    <!--[if IE 5.5]>
    According to the conditional comment this is Internet Explorer 5.5<br />
    <![endif]-->
    <!--[if IE 6]>
    According to the conditional comment this is Internet Explorer 6<br />
    <![endif]-->
    <!--[if IE 7]>
    According to the conditional comment this is Internet Explorer 7<br />
    <![endif]-->
    <!--[if gte IE 5]>
    According to the conditional comment this is Internet Explorer 5 and up<br />
    <![endif]-->
    <!--[if lt IE 6]>
    According to the conditional comment this is Internet Explorer lower than 6<br />
    <![endif]-->
    <!--[if lte IE 5.5]>
    According to the conditional comment this is Internet Explorer lower or equal to 5.5<br />
    <![endif]-->
    <!--[if gt IE 6]>
    According to the conditional comment this is Internet Explorer greater than 6<br />
    <![endif]-->
    </p>

    Note the special syntax:

    • gt: greater than
    • lte: less than or equal to

    CSS hack?

    Are conditional comments CSS hacks? Strictly speaking, yes, since they can serve to give special style instructions to some browsers. However, they do not rely on one browser bug to solve another one, as all true CSS hacks do. Besides, they can be used for more than CSS hacks only (though that rarely happens).

    Since conditional comments are not based on a browser hack but on a deliberate feature I believe they are safe to use. Sure, other browsers could implement conditional comments, too (though as yet none have done so), but they're unlikely to react to the specific query <!--[if IE]>.

    I use conditional comments, though sparingly. First I see if I can find a real CSS solution to an Explorer Windows problem. If I can't, though, I don't hesitate to use them.

    Comment tag

    A reader told me Explorer (Windows and Mac) supports the (non-standard) <comment> tag.

    <p>This is <comment>not</comment> Internet Explorer.</p>
    

    This is notInternet Explorer.

    This tag might come in handily if you want to use tags or styles for all non-Explorer browsers. Unfortunately these situations are rather scarce, especially since both Explorer Windows and Mac support this tag and you usually want to serve special content or style to only one of them.

    有兴趣的朋友直接可以查看:[http://www.quirksmode.org/css/condcom.html]

  • 相关阅读:
    CKEDITOR最新版不能上传图片的解决
    Java Web开发之Servlet获取ckeditor内容
    『实践』Java Web开发之分页(ajax)
    Java开发之JSP行为
    [Wpf学习] 1.传说中的Main
    直接使用汇编编写 .NET Standard 库
    ASP.NET CORE 启动过程及源码解读
    使用EventBus + Redis发布订阅模式提升业务执行性能(下)
    Android 实现浏览器跳转APP应用,网页也可以跳转APP
    Python全栈(七)Flask框架之1.Flask简介与URL和视图介绍
  • 原文地址:https://www.cnblogs.com/apexchu/p/1246603.html
Copyright © 2020-2023  润新知