简体   繁体   English

用于样式的移动设备类型检测?

[英]Mobile device type detection for styling?

Could anyone please advise on the best method to detect whether a site is being viewed on a mobile rather than a PC?任何人都可以就检测网站是否在移动设备而不是 PC 上查看的最佳方法提供建议吗? I would like to use a couple of mobile style sheets to suit each platform, but understand that iPhones/Android try to render the site as a PC rather than mobile?我想使用几个移动样式表来适应每个平台,但了解 iPhone/Android 尝试将站点呈现为 PC 而不是移动?

I guess a JavaScript detection script may be an option?我猜 JavaScript 检测脚本可能是一个选项?

How about using CSS @media ?使用CSS @media怎么样?

h2 {
  font-size: 12em;
}
@media (max-width: 320px) {
  h2 {
    font-size: 8em;
  }
}

As others have pointed out, the use of @media may work for newer mobile devices and may be sufficient for your needs.正如其他人所指出的,@media 的使用可能适用于较新的移动设备,并且可能足以满足您的需求。 I found this article to be very helpful for iPhone mobile website development. 我发现这篇文章对 iPhone 移动网站开发很有帮助。

If you need to do quality mobile detection on the server then you will need to get the server-side developers involved.如果您需要在服务器上进行高质量的移动检测,那么您需要让服务器端开发人员参与进来。 I use the Wurfl database in order to power our mobile detection on the server, which then directs the inclusion or exclusion of various stylesheets, scripts, and even some page workflows.我使用Wurfl 数据库来为服务器上的移动检测提供支持,然后它会指导包含或排除各种样式表、脚本甚至某些页面工作流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM