我有一个网页,为此我制作了两个 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/