适用于iPhone/Android的独家CSS

AKo*_*Kor 16 html css iphone mobile android

我正在为我的页面制作一个适合移动设备的样式表.有没有一种简单的方法可以让它向iPhone/Android用户展示样式表?或者我必须拉动用户代理并以此方式弄清楚 - 我该怎么做?

此外 - 任何使这种Web开发更容易的工具?

TNC*_*TNC 19

如果iOS/android的样式表相同,你可以这样做.

<link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="css/mobile.css" type="text/css" />

但是如果你想要检测它是iOS还是Android,那么你需要进行检测.

在使移动开发更容易的方面,有很多东西:

有几个让你开始:)

希望这可以帮助.


Kev*_*jak 6

试试这个,在 JavaScript 中使用 navigator.userAgent ;)(感谢这篇很棒的帖子http://css-tricks.com/snippets/javascript/redirect-mobile-devices/):

if ((navigator.userAgent.match(/iPhone/)) || (navigator.userAgent.match(/iPod/))) {
   alert("we've got an iDevice, Scotty");
}

if (navigator.userAgent.match(/Android/)) {
   alert("Droid me baby");
}
Run Code Online (Sandbox Code Playgroud)