Text Size units em and px

Source: Internet
Author: User

If we need to set the unit of text to EM. What should we do?

PX is a pixel, is the unit relative to the screen resolution, EM is relative to the browser default font size units, such as in the browser, the default text size is 16px, then the default 1em=16px. If we need to set the size of the text to EM, Then we need to calculate the size of the text we need to set relative to the default font size in multiples. For example, we want to set the font to 12PX, then 12/16=0.75em. We want to set the font unit to 10px, then 10/16=0.625em. This conversion can be cumbersome, usually we will change the body's default font to 10px, that is body{font-size:62.5%;} So when we want to set the font to 12 pixels, it is 12/10=1.2em. In fact, the calculation method has not changed, but it is very convenient to calculate.

Why would I set the unit of text to em?

Here are the reasons for the excerpt from the Bad Monk's blog HTTP://BLOG.SINA.COM.CN/ENXIAOP:

"Usually use PX to define the font, so the browser can not enlarge the font function, and most of the foreign sites are available under IE." because: 1. IE cannot adjust the font size of those using PX as unit; 2. Most of the foreign sites can be adjusted because they use the EM as font units; 3. Firefox can adjust px and em, but more than 96% of Chinese netizens use IE (or kernel). ”

Text Size units em and px

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.