Dp\dpi\px\pt\em Unit Length Understanding

Source: Internet
Author: User

The screen has a fixed physical long width attribute and resolution

Like a computer, like a phone screen.

For example, the phone screen size is 1.5 inches x2 inches, the screen resolution is 240x320,

Then you can calculate the number of pixels per inch (dpi) in the horizontal direction: 240/1.5=160, can also calculate the vertical direction per inch

1PX refers to a pixel on the screen, the principle of screen imaging is through the screen dense pixel point imaging;

Therefore, when the DPI of our screen is different, the length of 10px will display different physical lengths on the screen;

Android requires 4 four pixel densities: low (120DPI), Medium (160DPI), High (240dpi), and Ultra High (320DPI),

They correspond to a DP to PX coefficient of 0.75, 1, 1.5, and 2, which is multiplied by the DP length is the pixel number px

DP's appearance is to adjust the image display effect, so that we look the same object in different pixel density on the screen to show similar effect;

In a nutshell, the long-width DP of an object is specified on a different screen, and it is scaled according to the physical properties of the screen on different screens;

PT is the physical length unit, 1pt=1/72 inches = 0.035 centimeters;

EM is a bit similar to DP and is a relative unit of measure, pixel px is relative to the display screen resolution.
  EM is the relative length unit. The font size relative to the text within the current object. If the font size of the current inline text is not artificially set, the default font size is relative to the browser.
The default font height for any browser is 16px. All non-adjustable browsers are compliant with: 1EM=16PX. So 12px=0.75em,10px=0.625em.  To simplify the conversion of font-size, you need to declare font-size=62.5% in the body selector in the CSS, which makes the EM value 16px*62.5%=10px, so 12px=1.2em, 10px=1em, That means you just have to divide your original PX value by 10 and then put EM in as the unit.
  EM has the following characteristics:
1. The value of EM is not fixed;
2. Em inherits the font size of the parent element.
  So when we are writing CSS, we need to pay attention to two points:
1. Declare font-size=62.5% in the body selector;
2. Divide your original PX value by 10 and then replace it with EM as the unit;
3. Recalculate the EM values of the enlarged fonts. Avoid duplicate declarations of font size.
This is to avoid the 1.2 * 1.2 = 1.44 phenomenon. For example, when you declare a font size of 1.2em in #content, you can only have 1em when declaring the font size of p, not 1.2em, because this em is not em, it becomes 1em=12px because it inherits the font height of #content.
However, 12px Kanji exception, is obtained by the above method 12px (1.2em) size of Chinese characters in IE does not equate directly with 12px defined font size, but slightly larger. This problem Jorux has been solved, just in the body selector to change 62.5% to 63% can be displayed normally. The reason may be that when IE processes Chinese characters, the accuracy of the value of floating point is limited. I wonder if there is any other explanation.

Dp\dpi\px\pt\em Unit Length Understanding

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.