Html px em pt font size unit
Define the font size on the page there are three generic classes of units, px, em, pt
px
It is the abbreviation for pixel px, a change in the resolution of the unit pixels in the course of browsing, text on the screen, with the screen images and the like will vary based on, a 100px width size image at a resolution of 800 × 600, to accounting for 1/8 the width of the screen, but in the 1024 × 768, is only about 1/10. So if when you define the font size, use px as a unit, and that once the user to change the display resolution from 800-1024, the user will actually see the text change "small" (natural unit of length), or even see, the impact browsing.
in
em:% i.e., a relative unit, is a relative unit of length is the width of the initial letter M, named em. Now it refers to a multiple of the width of the character, similar to the percentage of usage, such as: 0.8em, 1.2em, 2em like. Usually 1em = 16px. Generally used to measure the common unit (e.g., element turnover margins and padding) length, when used to specify the font size, em unit refers to the font size of the parent element.
On one page a given font size of the parent element, so that you can be to alter the proportion of all elements by adjusting the size of an element. It can be freely scaled, such as used to make scalable style sheets.
pt
PT is Point (lb) abbreviation, is a fixed-length unit of measure, the size of 1/72 of an inch. If you are using the web to do in pt units of text, font size as in the different screen (same resolution), so that might affect the layout, but using pt in Word quite convenient. Because the main purpose is not to use Word to browse screen, but the printed output. When printing to the entity, pt as a natural unit of length on the convenient and practical: for example, Word documents are in common use "Times New Roman 9pt", Title "in bold 16pt" use and so on, no matter how computer settings, print it out forever is so big .
Change
The browser's default font height is 16px, so the unadjusted browser display 1em = 16px, that is 1px = 0.0625em. To simplify font-size conversion, you can css in the body of the first global declaration font-size = 62.5%, which is defined in the default font size is 16px * 0.625 = 10px, child elements will inherit the parent element's font size, Thus 1em = 10px, so 12px = 1.2em. em px and conversion can be obtained by 10. However, font-size = 0.625em defined or defined directly 12px, which had no effect. linkAndroid developers a common unit of measure
inch
1 inch is equal to about 2.54 cm, is mainly used to describe the size of the mobile phone screen.
DPI/PPI
DPI = Dots Per Inch
PPI = Pixel Per Inch
The difference is that the difference between two parameters of Pixel and Dot, dot value per a physical point on the display, and the pixel refers to a minimum unit in resolution of the screen. The two will not do the same? meeting! When more than one pixel requires a physical point on the screen to display just when the pixel is not the same dot. There is another name for this is called dppx (dot per pixel), that is, each pixel how many points. Most display a pixel that is a point, but some of the better screen and some cell phone screen dppx will be greater than 1. For example, Mac Retina, iPhone, HTC One and so on. I believe we have encountered some of the computer screen, it looks always so stupid silly big. Because they cause ppi resolution turned too low, and let the picture looks so incongruous. Look at the following two pictures, I am on a 1366x768 resolution monitor the effect of the resolution are set to 1366x768 and 1024x768 displayed.
1024 x 768
1366 x 768
But most cases we did not put two nouns points so clear, so when the two appear if the expression is basically the same thing, that is PPI (how many pixels per inch).
The PPI = the number of pixels of the screen diagonal / diagonal length of the screen = (√ (horizontal screen pixels ^ 2 + 2 ^ screen vertical pixels) / diagonal length)
For example: if a cell phone screen resolution of 720px * 1280px, 4.3 inches. The dot density is √ (720 ^ 2 + 1280 ^ 2) /4.3 = 342ppi. link
Resolution
Resolution of the word in many places, such as cameras, video scanners. Here that is the resolution of the display. Displays are composed of one pixel (pixel) composed generally of said display resolution is 1280x720 display would indicate that there are 1280 pixels in the horizontal direction, 720 pixels in the vertical direction. But not the higher the resolution the better screen display, also you need to be determined according to the size of the screen. That is to look at the density of pixels (pixel density), this indicator is the DPI (Dots Per Inch) or PPI (Pixels Per Inch), that is, the pixels on the screen or feet is the number of points.
Screen density
6.xxxhdpi: dpi in the range of 480 to 560
private void getDpi() {DisplayMetrics dm = getResources().getDisplayMetrics();Log.i("TAG", "density = " + dm.density);Log.i("TAG", "densityDpi = " + dm.densityDpi);}复制代码
density = 2densityDpi = 320复制代码
dp(dip)
Height: 1920/3 = 640dp , when we pay attention to the width of the design of the control value can not exceed the maximum width of the device.
sp
public static float applyDimension(int unit, float value,DisplayMetrics metrics) {switch (unit) {case COMPLEX_UNIT_PX:return value;case COMPLEX_UNIT_DIP:return value * metrics.density;case COMPLEX_UNIT_SP:return value * metrics.scaledDensity;case COMPLEX_UNIT_PT:return value * metrics.xdpi * (1.0f/72);case COMPLEX_UNIT_IN:return value * metrics.xdpi;case COMPLEX_UNIT_MM:return value * metrics.xdpi * (1.0f/25.4f);}return 0;}复制代码
return value * metrics.density;复制代码
To convert sp px, the code will be executed as follows:
return value * metrics.scaledDensity;复制代码
Change the density, scaledDensity and resolution in the Android system settings menu
Usually we do in the UI to fit the page, it will go to a lot of different Android devices, in fact, we only need to go to the system menu to set density, scaledDensity and resolution of these parameters, then you can on an Android device see page show the effect on different Android devices to huawei mate8 phone, for example, enter the system setup menu display items:
Change the density and resolution by ADB shell command
View supported at the terminal input adb shell wm command set:
Change and view density command:
Change the resolution and view command:
Reproduced in: https: //juejin.im/post/5cf1fa70f265da1bb31c207e