iphone - 如何从 iphone 浏览器隐藏桌面 css?

标签 iphone css browser safari

我有一个网页,为此我制作了两个 css 文件,一个用于桌面浏览器,另一个用于 iphone。 我这样做是这样的:

<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="/css/main.css" media="screen,projection,print" />
<link rel="stylesheet" href="/css/mobi.css" type="text/css" media="only screen and (max-device-width: 480px)" />

在桌面上它工作正常,但在 iphone 上我有一些奇怪的行为,看起来它同时加载文件和规则相互冲突。如果我注释掉第二行 (main.css) 它在 iphone 上工作正常。

那怎么隐藏呢? 谢谢

最佳答案

我包含了 WHOISSTAN 的 php 函数示例,来自 http://mobiforge.com :

function is_mobile(){
    $regex_match="/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|";
    $regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|";
    $regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|";    
    $regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|";
    $regex_match.="jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220";
    $regex_match.=")/i";        
    return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']));
}

然后我在我的 <HEAD></HEAD> 中添加了这个标签:

<?php
    if(is_mobile()) {
        ?><link rel="stylesheet" href="mobi.css" type="text/css" media="handheld" /> <?php 
    } else { 
        ?> <link rel="stylesheet" href="main.css" type="text/css" media="screen" /> <?php
    } ?>

关于iphone - 如何从 iphone 浏览器隐藏桌面 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4739086/

相关文章:

iphone - ios<= 6 中的 cocos2d 方向问题

iphone - 如何使用iPhone内置的PDF查看器显示文档

ios - 在 Swift 中从登录 Storyboard 迁移到主 Storyboard,无需发出警告

javascript - 可编辑选择无法正常工作

html - 浏览器默认样式

ios - 如何将 Storyboard UIViewController 与我的自定义 UIViewController 类相关联?

jquery - 垂直居中响应图像

javascript - 使用 JavaScript 编辑 CSS 渐变

CSS3 SVG 动画在 Safari 中不起作用

javascript - 带有引导模式框的自定义选择框错误