Pixels and viewport in the mobile web

Source: Internet
Author: User

Device Pixel:The minimum physical display unit for the display. The screen parameters of a mobile device, such as 1920x1080, refer to the device pixels.device Density (ppi/dpi):The number of device pixels included in the length of the display per inch. In iOS, the display with a PPI greater than 320 is called retina. Android uses ldpi (120~160), MDPI (160~240), hdpi (240~320), xhdpi (>320) to rank the display.Device-independent pixels (Devices independent Pixel):The unit of virtual pixels used to set the interface display, device-independent pixels can be larger or smaller than the device pixels.  The CSS pixel of the page, and the resolution pixel set by the PC Monitor, refers to this pixel. You can adjust the size of a single device-independent pixel by scaling the page, or by setting the display's resolution.device pixel ratio (devicepixelratio):The ratio of the number of device pixels and device-independent pixels that the display holds.  In the browser, this value is related to the scaling of the page. Support for some browsers gets the value by Window.devicepixelratio.Viewport:  The parent container of the page HTML element, which is equal to the width of the viewport when the HTML setting is 100% width. On the PC browser, the width of the viewport is the same as the width of the viewable area of the browser, not necessarily on the mobile browser, most mobile browsers default viewport width is 980px.   In the page, you can set the width=device-width width by <meta name= "viewport" content= "/>" viewport. The value of width can be device-width, or an integer. The width unit of the viewport is PX, and the PX here refers to device-independent pixels (CSS pixels). Because the default scaling of different models and browsers is not the same, when you open a page that is not set viewport by these browsers, the width of the page visually is not the same. The default scaling strategy for iOS is that the page does not appear with scroll bars, which fills the viewable area of the browser, at which point the device pixel width (in units pixels px)/default viewport width (980px, device-independent pixel px). The default scaling strategy for Android is different, and some, like iOS, are calculated based on the default value of target-densitydpi medium-dpi.   What is the value of this device-width, the width=device-width mentioned above? On different devices, the pixel size of a single device is not the same, so that the same page will have a completely different effect on those devices. To solve this problem, you need to display a Web page on a different device, and the width of a single CSS pixel is the same in the CSS pixel used. Early devices, such as the iphone,3.5 inch size of the first version, have a device pixel of 320, and the device pixels are equal to the CSS pixels. Later the device pixel value of the new device is increasing, and the screen size does not increase too much, so that the width of a single device pixel is smaller, a single CSS pixel needs to contain multiple device pixels, to ensure that the size of a single CSS pixel and the old version of the device basically equal, so that each device has its own ideal device pixel ratio. The device pixel width of this device/  this ideal device pixel ratio, get the device-width value, on iOS is 320, on Android, there are 320, 360, 384, 400 and other different values.   in media query, device-width refers to device pixels, which are not the same as the values here.

Moving pixels and viewport in the Web

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.