【问题标题】:Is there any equivalent to IE conditional comment for chrome and safari?chrome 和 safari 是否有相当于 IE 条件注释的内容?
【发布时间】:2011-01-04 08:45:20
【问题描述】:

我想知道是否有任何东西可以像 webkit 的条件注释一样工作。

我想改变宽度。

例如,

<!--[if IE]>
<link href="css/ie.css" rel="stylesheet" type="text/css" />
<![endif]-->

提前致谢。

【问题讨论】:

  • IE 的条件 cmets 是 HTML cmets 而不是 CSS cmets。
  • 你说的很对。已更新。

标签: css safari webkit google-chrome


【解决方案1】:

不,没有。

您可以通过在 JS 中进行浏览器检测并动态附加脚本/样式来破解它。

或者,如果您只关心为不同的浏览器使用不同的 css,您可以使用 css hacks。可能有适用于您需要的浏览器的 css hack。

或者,如果您唯一需要更改的是“宽度”(一个 css 定义?),您可能可以在 jquery 或 javascript 中进行更改

jquery 浏览器检测。看: http://docs.jquery.com/Utilities/jQuery.browser

【讨论】:

  • 是的。试试 $.browser.msie == true。 $.browser.mozilla == true 等检查 $.brower 对象或阅读文档
  • 看了你的回复后,我发现了这个,而且效果很好。谢谢。 tvidesign.co.uk/blog/…
  • 但是如果我使用电子邮件模板并想检测 iPhone?我不能使用脚本。有什么方法可以隐藏或显示一些专门为 iPhone 设计的 html 标记?
【解决方案2】:

我在每个项目中都使用它: http://rafael.adm.br/css_browser_selector/

不过,如果您必须在 Firefox 或 Webkit 中进行大量定位,您可能需要重新考虑编写 HTML/CSS 的方式。

【讨论】:

    【解决方案3】:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Browsser Detection</title>
    
    <link rel="stylesheet" href="Main.css" type="text/css">
    
    <?php 
    
    $msie        = strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE') ? true : false; 
    $firefox    = strpos($_SERVER["HTTP_USER_AGENT"], 'Firefox') ? true : false;
    $safari        = strpos($_SERVER["HTTP_USER_AGENT"], 'Safari') ? true : false;
    $chrome        = strpos($_SERVER["HTTP_USER_AGENT"], 'Chrome') ? true : false;
    
    if ($msie) {
    echo '
    <!--[if IE 7]>
    <link rel="stylesheet" href="ie7.css" type="text/css">
    <![endif]-->
    <!--[if IE 8]>
    <link rel="stylesheet" href="ie8.css" type="text/css">
    <![endif]-->
    ';
    }
    if ($safari) {
    echo '<link rel="stylesheet" href="safari.css" type="text/css">';
    }
    
    ?>
    
    </head>
    <body>
    
        <br>
        <?php
        if ($firefox) { //Firefox?
        echo 'you are using Firefox!';
        }
    
        if ($safari || $chrome) { // Safari?
        echo 'you are using a webkit powered browser';
        }
    
        if (!$msie) { // Not IE?
        echo '<br>you are not using Internet Explorer<br>';
        }
        if ($msie) { // IE?
        echo '<br>you are using Internet Explorer<br>';
        }
        ?>
    
        <br>
    
    </body>
    </html>
    

    来自Chrome conditional comments

    【讨论】:

      【解决方案4】:

      一个基于 CSS 的解决方案是答案 here。它对 webkit 浏览器的支持非常广泛。

      【讨论】:

        猜你喜欢
        • 2012-04-26
        • 2014-03-22
        • 1970-01-01
        • 2013-10-08
        • 2016-12-16
        • 2016-02-10
        • 1970-01-01
        • 2016-07-22
        • 2010-11-20
        相关资源
        最近更新 更多