The difference and application of px, EM and rem in CSS

Source: Internet
Author: User

First: The difference between the Px,em,rem.

PX is an absolute font size
EM is the relative font size calculated based on the cardinality (for example: 1.5em). This cardinality is multiplied by the current object from its parent to the genetic font size.
REM is computed based on the font size of the root node, such as HTML.

First say EM if your default parent container font is 16PX, then 2em=2*16px

<div class= "Parent" style= "font-size:16px" >
    <p style= "Font-size:2em" > I am the EM test </p>
</ Div>

rem default font size is determined by the browser or other device you are using in your site's current visit, especially for response design, which has been sought after by mobile design.

<! DOCTYPE html>

See on the Internet
to make the conversion easier, you can set the default font size to 62.5% or 10px to facilitate calculation.
Most browsers (excluding IE8 below) support the font size of REM units
If you want to support, you can, as follows:

HTML {font-size:62.5%;}
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.