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
- EM is based on the current element (if not set to inherit its parent element) Font-size, so there will be some combinatorial problems;
- 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
- (a) EM, PX, PT, CM, in ...
- Understanding the length units in CSS
- CSS3 Tutorial: Relative unit REM Detailed
- IE8 Hack Introduction
[CSS3 Tutorial] relative unit REM detailed