What is the difference between max-device-width and max-width for mobile web?

前端 未结 8 1949
盖世英雄少女心
盖世英雄少女心 2020-11-22 08:56

I need to develop some html pages for iphone/android phones, but what is the difference between max-device-width and max-width? I need to use diffe

相关标签:
8条回答
  • 2020-11-22 09:57

    max-width refers to the width of the viewport and can be used to target specific sizes or orientations in conjunction with max-height. Using multiple max-width (or min-width) conditions you could change the page styling as the browser is resized or the orientation changes on a device like an iPhone.

    max-device-width refers to the viewport size of the device regardless of orientation, current scale or resizing. This will not change on a device so cannot be used to switch style sheets or CSS directives as the screen is rotated or resized.

    0 讨论(0)
  • 2020-11-22 09:58

    What do you think about using this style?

    For all breakpoints which are mostly for "mobile device" I use min(max)-device-width and for breakpoints which are mostly for "desktop" use min(max)-width.

    There are a lot of "mobile devices" that badly calculate width.

    Look at http://www.javascriptkit.com/dhtmltutors/cssmediaqueries2.shtml:

    /* #### Mobile Phones Portrait #### */
    @media screen and (max-device-width: 480px) and (orientation: portrait){
      /* some CSS here */
    }
    
    /* #### Mobile Phones Landscape #### */
    @media screen and (max-device-width: 640px) and (orientation: landscape){
      /* some CSS here */
    }
    
    /* #### Mobile Phones Portrait or Landscape #### */
    @media screen and (max-device-width: 640px){
      /* some CSS here */
    }
    
    /* #### iPhone 4+ Portrait or Landscape #### */
    @media screen and (max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2){
      /* some CSS here */
    }
    
    /* #### Tablets Portrait or Landscape #### */
    @media screen and (min-device-width: 768px) and (max-device-width: 1024px){
      /* some CSS here */
    }
    
    /* #### Desktops #### */
    @media screen and (min-width: 1024px){
      /* some CSS here */
    }
    
    0 讨论(0)
提交回复
热议问题