The thing in CSS (a)---units in CSS 2

Source: Internet
Author: User

In the previous blog mentioned%, px, em three units, the most complex is EM, because to calculate the current element within the font-size, you must know the parent element of the font-size, layer accumulation, error prone. Now the new unit REM has been introduced into the CSS3, which has changed the status quo.

Rem

REM, official saying: The root element of the font-size. The official said this very clearly, REM is relative to the root element of the HTML to calculate, the root of the current element of the immediate parent element is independent, as long as the HTML settings font-size, the default is 1rem=16px. Let's look at an example below:

 .container  {width :  80% ; height :  10em ; padding :  1em ; background-color :  #228F45 ; font-size :  1.5rem ;} .child  {width :  50% ; height :  5em ; background-color :  #D5DED8 ; padding :  0.8em ; font-size :  0.8rem ;} 

HTML under 1rem=16px,container under Font-size=1.5*16=24px,1em=24px,height=24*10=240px,child font-size=0.8*16=12.8px,1em= 12.8px,height=12.8*5=64px. Of course, IE8 and the lower version of IE is not support REM, so in consideration of compatibility, you can use PX to hack.

Other

Other units in, CM, MM, PT, PC are absolute units, these units in the web used relatively little, and PX conversion relationship as follows
1in = 2.54cm = 25.4 mm = 72pt = 6pc = 96px

Summarize

At present these units are widely used in the px,em,rem,%, now very popular bootstrap more use of EM, if not support IE8, you can consider using REM, figuring out the situation of these units, in favor of the layout of the picture preparation.

The thing in CSS (a)---units in CSS 2

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.