Search code examples
javascriptmobilehtml5boilerplate

How can I detect if a browser is mobile and switch between normal and mobile?


I assume it involves the view-port somehow, but I'm not good at mobile. I'd like to re-size my font and move my elements around.

I see that HTML 5 Boilerplate comes in a mobile form, how and when would I switch to that?


Solution

  • You may parse the user agent to determine the mobile platform (e.g., iPhone, iPad, iPod, Android, Opera, Android, BlackBerry, hpwOS, Windows PhoneOS, etc.).

    And it is better to use a @media query in CSS to take advantage of the screen dimensions.

    For reference: