Mobile Web One pixel problem

Source: Internet
Author: User

One, why there is a pixel problem

To understand this problem, we must first know the DPR.

The DPR (device pixel ratio) pixel equals the picture element. Device pixel ratio, which is the default scale of 100%, that is, the number of dpr= device pixels/The number of ideal viewport pixels (device-width).

1. Device pixels: physical pixels of the device, the physical pixels of any device are fixed.

2. Layout viewport: The viewport on which the CSS layout is moved, that is, the CSS layout is calculated based on the layout viewport. The ideal viewport is the ideal layout viewport.

Take IPhone6 as an example, when we write a pixel line border-top:1px solid red, when the screen shows the red line of 1px? Obviously not. The layout viewport is the base viewport for the mobile side of our CSS layout, and the layout viewport is set to the ideal viewport when we set <meta name= "viewport" content= "Width:device-width" >. IPhone6 dpr=2, so the screen is actually the red line of 2px. Some people say that we write the CSS layout when writing border-top:0.5 solid red; The idea is good, but the computer calculates 0.5 as 1.
Second, Transform:scale

The solution here is to scale this line, using pseudo-elements:: Before or:: After to implement a pixel border, and then use the @media to fit different device pixel ratios to determine the scale.

. Border-top{position:relative;}. Border-top::before{position:Absolute;Top:0; Left:0;content: " ";width:100%;Height:1px;Background-color:#e4e4e4;-webkit-transform-origin:Left Bottom;Transform-origin:Left Bottom;}/*twice times screen*/@media (-webkit-min-device-pixel-ratio:2.0), (min-device-pixel-ratio:2.0){. Border-bottom:: Before {-webkit-transform:scaley (0.5);Transform:ScaleY (0.5); }}/*3 times times Screen*/@media (-webkit-min-device-pixel-ratio:3.0), (min-device-pixel-ratio:3.0){. Border-bottom:: Before {-webkit-transform:scaley (0.33);Transform:ScaleY (0.33); }}

  

Mobile Web One pixel problem

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.