The difference between/px/em/rem/

Source: Internet
Author: User

PX Features:

1. IE cannot adjust the font size using PX as the unit;

2. Most of the foreign sites can be adjusted because they use EM or REM as font units;

3.Firefox can adjust px and em,rem, but more than 96% of Chinese netizens use IE browser (or kernel). px Pixels (Pixel). Relative length units. 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.

**任意浏览器的默认字体高都是16px。所有未经调整的浏览器都符合: 1em=16px。那么12px=0.75em,10px=0.625em。为了简化font-size的换算,需要在css中的body选择器中声明Font-size=62.5%,这就使em值变为 16px*62.5%=10px, 这样12px=1.2em, 10px=1em, 也就是说只需要将你的原来的px数值除以10,然后换上em作为单位就行了。

*************************************************************************************************************** **

EM features:

    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:

    3. The body selector declares the font-size=62.5%;

    4. Divide your original PX value by 10 and then replace it with EM as the unit;

    5. Recalculate the EM values of those magnified 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.

***************************************************************************************************************

REM Features:

rem是CSS3新增的一个相对单位(root em,根em),这个单位引起了广泛关注。这个单位与em有什么区别呢?区别在于使用rem为元素设定字体大小时,仍然是相对大小,但相对的只是HTML根
元素。这个单位可谓集相对大小和绝对大小的优点于一身,通过它既可以做到只修改根元素就成比例地调整所有字体大小,又可以避免字体大小逐层复合的连锁反应。目前,除了IE8及更早版
本外,所有浏览器均已支持rem。对于不支持它的浏览器,应对方法也很简单,就是多写一个绝对单位的声明。这些浏览器会忽略用rem设定的字体大小。下面就是一个例子:p {font-size:14px; font-size:.875rem;}
选择使用什么字体单位主要由你的项目来决定,如果你的用户群都使用最新版的浏览器,那推荐使用rem,如果要考虑兼容性,那就使用px,或者两者同时使用。

/px/em/rem/the difference

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.