The difference between the unit PX and EM in the detailed CSS

Source: Internet
Author: User
The use of PX to define fonts, can not be used to enlarge the browser font, and most foreign sites can be used in Internet Explorer.

Reason:

1.IE cannot adjust the font size for PX units.

2. Most foreign countries use EM as font units.

Px,em are relative length units,

PX is relative to the display resolution.

EM is the font size relative to the text within the current object, relative to the default font size of the browser, if the text font size in the current object is not set by a person.

The default font for any browser is 16px, and all browsers that are not set up conform to: 1em=16px. So 12px=0.75em,10px=0.625em. In order to simplify the conversion of font-size, it is necessary to declare font-size=62.5% in the body selector in CSS, which makes EM refers to 16px*62.5%=10px, so 12px=1.2em,10px=1em, In other words, the original PX value is divided by 10 and then replaced by the EM unit.

EM has the following characteristics:

The value of 1.em is not fixed.

2.em inherits the font size of the parent element.

It is therefore necessary to emphasize:

Declaring font-size=62.5% in the 1.body selector

2. Divide the original PX value by 10 and then replace it with the EM unit

3. Recalculate the EM value of the magnified font, avoiding duplicate declaration of font size.

Precautions:

The 12px (1.2EM) characters obtained by using the above method are not equal to the font size defined by 12px directly in IE, but slightly larger.

You need to change 62.5% to 63% in the body selector to display it properly.

The reason may be that when IE handles Chinese characters, the value of floating point is limited in accuracy.

The above is a small part of the introduction of a thorough understanding of the CSS in the unit PX and the difference between EM, I hope we have some help, if you have any questions please give me a message, small series will promptly reply to you. Thank you very much for your support for topic.alibabacloud.com!

Related Article

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.