Understanding Em,rem

Source: Internet
Author: User

In the usual web site to write code when the general use of PX, in the previous study on a little learning about the EM, rem knowledge, but because has not been used, so almost all forgotten. Today in the study of some knowledge of the use of EM, so deliberately to learn the knowledge summed up.

1.em

EM is the relative length unit, relative to the font size in the yourselves object. For example, in a div font-size set to 20px, then 1em is equivalent to 20px,0.25em equivalent to 5px. Because the browser's default font size is 16px, so in order to simplify the conversion of font-size, it is necessary to set the font-size in the body selector to 62.5%, converted to pixels, is 16*62.5%=10px, In this way after the size of the set can be used to 1.2em for 12px, that is, the conversion relationship at this time is 1em=10px.

It is important to note that EM integrates the font size of the parent element. So don't change em in the current element easily.

2.rem

REM and EM have similar methods of use, all of which are relative length units. The difference is that REM needs to set font-size in the CSS selector of the root element HTML and set Font-size to 14px, then 1rem is 14px. The advantage of using this length unit is that it can be used to fit. You can change font-size directly in

Source: http://www.cnblogs.com/leejersey/p/3662612.html

Understanding Em,rem

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.