An article that really teaches you to develop mobile pages (ii)
PSD diagram:
Now the mobile side of the design is generally based on iphone5 (640px) and Iphone6 (750px), the lower left corner of PS magnification to 100%, see the width is how much, is the number of whichever. This article is based on Iphone6 (750px), the other dimensions of the same principle. PSD Originals are designed according to device pixels.
Iphone5 Ideal viewport pixels: 320*568
The iphone5 device pixels are: 640*1136;
dpr=2
Iphone6 Ideal viewport pixels: 375*667
The iphone6 device pixels are: 750*1334;
dpr=2
dpr= number of device pixels/number of ideal css pixels
The Global Properties of window can test the device ratio: devicepixelratio
Web development is based on layout viewports and now sets the width of the layout viewport to the width of the ideal viewport, width=device-width,
So now the width of the screen in your eyes corresponds to the CSS pixel is 375*667;
Example one:
The first step
You measured the PSD on the previous square: 200px*200px
You write on the code 200*200px, open the browser a look, dumbfounded, the proportion is obviously wrong.
Reason: PSD manuscript size is designed according to the device pixel, we follow the size of the Phone6, so the size of the design draft is IPHONE6 device pixel size, is 750*1334, and our CSS style is based on the layout viewport calculation, because the page is written on the label
<mata name= "viewport" content= "width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=" no "/>
Width=device-width This code is to make the layout viewport equal to the ideal viewport, resulting in: The layout viewport is 375*667px,
The 200*200 you wrote was based on 750*1334,
And your CSS corresponds to the screen is 375*667;
So wrong;
FIX: width:100px height:100px, it's normal.
Part II:
According to the above, the PSD total width of 750px, measured element width 200px, and we really do page based on the layout viewport, layout viewport is 375px, just half of the design manuscript, so should be measured to divide by 2, so modify the code: 100px*100px, now the same effect
However, we know that the measurement is divided by 2,111 divided by 2 to 55.5, the computer or phone can not display the pixel value of 1 pixels, the computer or phone will be automatically complete 1, the display is 56 pixels, this is not what we want.
The layout viewport = Ideal viewport is already written on the page
Scaling ratio of 1 DPR (devicepixelratio) = device/ideal (screen width CSS, developer's eye CSS)
Element device Pixel
Question: 200*200 750*1334 Design Draft
Element CSS Ideal Viewport screen width
100*100 375*667 Iphone6
100*100 x 414*736 7plus Scale is inconsistent, so you can't just divide it by 2.
750/414=200/x x=200* (414/750) x= Test * (device ideal viewport width/psd width)
So:
Different phones, the layout viewport (now also equal to the ideal viewport is equal to the screen width) is not the same, the proportions are inconsistent, so can not be directly divided by 2. Dividing directly by 2 cannot be displayed intact on all devices
So: If the layout viewport size = = Device pixel size, then the measured size can be directly used in the development of the page, the other mobile phones, only need to do the scaling is OK
If: We change the ideal viewport size, it will change the layout of the viewport size,==> measurement is written; How to change the ideal viewport size? How to make the ideal equal to the device?
Solution: Scaling is the process of narrowing or magnifying the CSS, taking iphone6 as an example, since Iphone6 's DPR is 2, when the scaling ratio is 1,
A CSS pixel size corresponds to 2 device pixel dimensions,
When a CSS pixel is reduced to the original half, that is 0.5 times times the original, reducing the multiplier = device pixel ratio of the reciprocal;
Resolution: Scale=1/window.devicepixelratio set scale dynamics to ensure that the layout is always equal to the device
The layout is always equal to the device, it will appear the test is written;
width:200px height:200px
The third step: iphone5 and iphone6 contrast effect, because iphone5 and iphone6 device pixels inconsistent, ihpone6 maintain consistent with the design diagram, and iphone5 inconsistent. Effect deviation
Solution: Using REM
An article that really teaches you to develop mobile pages (ii)