[CSS3 Tutorial] relative unit REM detailed

Source: Internet
Author: User

zhanhailiang 日期:2015-01-28
Defined

CSS3 has added a relative unit REM, which is officially defined as follows:

Font size of the root element

The difference between REM,EM,PX units

REM Units and EM units are relative in size, px is absolute size. Its difference in

    1. EM is based on the current element (if not set to inherit its parent element) Font-size, so there will be some combinatorial problems;
    2. REM is a font-size only relative to the root element, that is, only the font-size of the roots is set, and the other elements are set to the corresponding percentages using REM units;
Compatibility notes

Currently, in addition to IE8 and earlier versions, all browsers support REM. For browsers that do not support it, the workaround is simple enough to write an absolute unit statement. These browsers ignore font sizes that are set with REM.

Example
<HTML><Head> <Meta http-equiv= "content-type"  content= "text/html; Charset=utf-8" /><style>/ * Browser default font-size:16px;*/    /*% units for font-size, line-height, etc., are based on the font-size;*/of their parent elements    /*16px * 312.5% = 50px;*/     html{font-size: 312.5%;}    /*50px * 0.5 = 25px; IE8 and Previous versions use */     body{font-size: 0.5rem; font-size:px;}    /*50px * 0.25 = 12px; IE8 and Previous versions use */     p{font-size: 0.25rem; font-size:px;}    </style></Head><Body> Browser Default font-size:16px;<P> Browser Default font-size:16px;</P></Body>
Read more
    1. (a) EM, PX, PT, CM, in ...
    2. Understanding the length units in CSS
    3. CSS3 Tutorial: Relative unit REM Detailed
    4. IE8 Hack Introduction

[CSS3 Tutorial] relative unit REM detailed

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.