[HTML5] Phone screen resolution and browser resolution

Source: Internet
Author: User

There are similar codes in the use of CSS3

HTML code
    1. @media screen and (max-width:480px) {
    2. ......

This means that the style of {} is applied on devices with a maximum width of 480px. The width here, note is the resolution of the phone browser, not the screen resolution of the mobile device. For example, Apple's 4 phone screen resolution is 960x640. The resolution of its own Safari browser is 320*480. We can detect the resolution of the browser using the following code:

JS Code
    1. $ ("#info"). HTML ("Your browser has a resolution of:" + ($ (document). Width () + "*" +$ (document). Height ()) + ")");

HTML code
    1. <div id= "Info" ></div>

On many Android devices, the system comes with a browser, Chrome browser, QQ browser, UC, etc., the value of the test is not the same. This brings complexity to the development of mobile web. Testing will also be different in a desktop browser.

When we do web development for mobile phones, we usually include them in the head:

HTML code
    1. <meta name= "viewport" content= "Width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" >

The device-width here is also the width of the browser used by the value, not the phone itself.

Please advise me if you are wrong.

====================== Split Line ===========================

Useful JS Detection code:

JS Code
  1. /*
  2. * Smartphone browser version information:
  3. *
  4. */
  5. var browser = {
  6. Versions:function () {
  7. var u = navigator.useragent, app = Navigator.appversion;
  8. return {//Mobile terminal browser version information
  9. Trident:u.indexof (' Trident ') >-1,//ie core
  10. Presto:u.indexof (' presto ') >-1,//opera core
  11. Webkit:u.indexof (' AppleWebKit ') >-1,//Apple, Google kernel
  12. Gecko:u.indexof (' Gecko ') >-1 && u.indexof (' khtml ') = =-1,//Firefox kernel
  13. Mobile:!! U.match (/applewebkit.*mobile.*/) | | !! U.match (/applewebkit/),//Whether it is a mobile terminal
  14. Ios:!! U.match (/(i[^;] +;( U;)? Cpu.+mac OS X)/),//ios terminal
  15. Android:u.indexof (' Android ') >-1 | | U.indexof (' Linux ') >-1,//android terminal or UC Browser
  16. Iphone:u.indexof (' IPhone ') >-1 | | U.indexof (' Mac ') >-1,//whether for iphone or Qqhd browser
  17. Ipad:u.indexof (' ipad ') >-1,//whether ipad
  18. Webapp:u.indexof (' Safari ') = =-1
  19. Whether the web should program, no head with the bottom
  20. };
  21. }(),
  22. Language: (Navigator.browserlanguage | | navigator.language). toLowerCase ()
  23. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.