简体   繁体   中英

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? 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?

I guess a JavaScript detection script may be an option?

How about using 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. I found this article to be very helpful for iPhone mobile website development.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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