0

只有在检查它是否为 ipad 后,我才需要停止包含特定的 CSS 文件

这可以使用javascript或css来完成吗

就像是

<!--[if !isAppleProduct()]>
   <link href="./css/fluid.css" type="text/css" rel="stylesheet" />
<![endif]-->
4

4 回答 4

1

您使用的条件注释语法是 IE 独有的功能(在 IE10 中已停用),因此您无法使用它来检测其他任何内容。

但是,使用 JavaScript,您可以执行以下操作;

if (navigator.userAgent.indexOf("iPad") > -1) {
    // add classname "iPad" to the <body>
    document.body.classList.add("iPad");
}

然后,您可以在任何 CSS 规则前面加上.iPad仅适用于 iPad。

.iPad .myClass {
    /* iPad-specific css */
}

或者,您可以使用相同的测试来包含特定于 ipad 的 css 文件:

if (navigator.userAgent.indexOf("iPad") > -1) {
    var ipadCss = document.createElement("link");
    ipadCss.type = "text/css";
    ipadCss.rel = "stylesheet";
    ipadCss.href = "/path/to/ipad.css";
    document.head.appendChild(ipadCss);
}
于 2013-08-27T07:31:42.297 回答
0
@media only screen and (not (min-device-width : 768px)) and (not (max-device-width : 1024px)),
only screen and (not (min-device-width : 320px)) and (not (max-device-width : 568px)),
only screen and (not (min-device-width : 320px)) and (not (max-device-width : 480px)){
    /* CSS for Apple product here */
}

第一行为 iPad 启用 CSS,第二行 - 适用于 iPhone5,第三行 - 适用于 iPhone4 或更早版本

于 2013-08-27T07:26:57.047 回答
0

将其放入 header.php

<?php 
    $iPod    = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
    $iPhone  = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
    $iPad    = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
    if( $iPod || $iPhone || $iPad){ ?>
        <style type="text/css">
           /* put your css code */
    }
        </style>
    <?php }
?>

谢谢

于 2014-01-28T08:49:44.777 回答
0

您可以使用headjs。您可以通过识别来检测平台/设备的类型,userAgent然后基于此有条件地加载 css。

于 2014-03-14T10:24:44.980 回答