【问题标题】:How does the "IE6 no more" code work?“不再使用 IE6”代码是如何工作的?
【发布时间】:2009-08-06 01:17:02
【问题描述】:

IE6 No More website上有代码示例,比如这个:

<!--[if lt IE 7]>
<div style='border: 1px solid #F7941D; background: #FEEFDA; text-align: center; clear: both; height: 75px; position: relative;'>
  <div style='position: absolute; right: 3px; top: 3px; font-family: courier new; font-weight: bold;'><a href='#' onclick='javascript:this.parentNode.parentNode.style.display="none"; return false;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-cornerx.jpg' style='border: none;' alt='Close this notice'/></a></div>
  <div style='width: 640px; margin: 0 auto; text-align: left; padding: 0; overflow: hidden; color: black;'>
    <div style='width: 75px; float: left;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-warning.jpg' alt='Warning!'/></div>
    <div style='width: 275px; float: left; font-family: Arial, sans-serif;'>
      <div style='font-size: 14px; font-weight: bold; margin-top: 12px;'>You are using an outdated browser</div>
      <div style='font-size: 12px; margin-top: 6px; line-height: 12px;'>For a better experience using this site, please upgrade to a modern web browser.</div>
    </div>
    <div style='width: 75px; float: left;'><a href='http://www.firefox.com' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-firefox.jpg' style='border: none;' alt='Get Firefox 3.5'/></a></div>
    <div style='width: 75px; float: left;'><a href='http://www.browserforthebetter.com/download.html' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-ie8.jpg' style='border: none;' alt='Get Internet Explorer 8'/></a></div>
    <div style='width: 73px; float: left;'><a href='http://www.apple.com/safari/download/' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-safari.jpg' style='border: none;' alt='Get Safari 4'/></a></div>
    <div style='float: left;'><a href='http://www.google.com/chrome' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-chrome.jpg' style='border: none;' alt='Get Google Chrome'/></a></div>
  </div>
</div>
<![endif]-->

这是如何工作的?为什么在 IE6 上会显示,而在较新的浏览器上却不显示?

【问题讨论】:

    标签: css internet-explorer-6


    【解决方案1】:

    因为这个:

    <!--[if lt IE 7]>
    ...
    <![endif]-->
    

    这是一个只有IE类型浏览器才能识别的标签,英文是“if browser version is less than IE7, show this”。

    【讨论】:

    • 啊,呃。我读起来好像这两行是 cmets,中间的代码不是注释的一部分。谢谢:)
    【解决方案2】:

    Conditional Comments

    ...这是 IE 特有的功能,可让您针对不同版本的浏览器。

    【讨论】:

      【解决方案3】:

      这段代码“询问”浏览器它是哪个版本(使用浏览器的user agent)。如果它是“小于”(lt)IE 7(所以 IE 6、IE 5、IE 4、IE 3、IE 2、IE 1),那么它会显示两个标签之间的 HTML。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-27
        • 1970-01-01
        相关资源
        最近更新 更多