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