Html加载css如果检测到移动

时间:2012-05-22 16:36:46

标签: html css mobile

<link media="only screen and (min-device-width : 320px) and (max-device-width : 480px)" href="smartphone.css" type= "text/css" rel="stylesheet" />
<link media="only screen and (-webkit-min-device-pixel-ratio : 1.5), only screen and (min-device-pixel-ratio : 1.5)" href="iphone.css" type= "text/css" rel="stylesheet" />
我正在做对吗?还是有更好的方法来做到这一点?

2 个答案:

答案 0 :(得分:0)

您可以查看te用户代理并使用php加载适当的用户代理。然而,使用它限制你到320-480。我认为Blackberrys就像240x320(至少是9xxx系列)

答案 1 :(得分:0)

与Cole提到的一样,您可以查看userAgent。这是一些javascript,您可以用来检测userAgent是否是iphone。 (Source

<script language=javascript>
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
//Change the css
}
-->
 </script>