4.CSS Unit of Measure

Source: Internet
Author: User

In CSS length settings, we often need to use the unit of measure, that is, in what units to design our font or border length. In CSS, the length unit is divided into absolute length and relative length.

Absolute length refers to the real-world unit of measurement, and CSS supports five absolute-length units.

Absolute length Unit

Unit identifiers Description
Inch Inches
Cm Cm
Mm Mm
Pt Pounds
Pc Pica

 

Relative length refers to other types of units, but also five kinds.

Relative length Units

Unit identifiers Description
Em Hook with element font size
Ex Hook to the "x-height" of the element font
Rem Hook to the font size of the root element
Px Pixels, linked to resolution
% Percentage relative to another value

Below we use some common units as a demonstration, rather than the basic use of the demo.

1.em relative units

{    margin: 0;      padding: 0;      background: silver;      font-size: 15px;      height: 2em

Explanation: EM is a relative unit, linked to the font size, will change its size depending on the font size, flexibility is high.

2.px relative units, absolute characteristics

{    margin: 0;      padding: 0;     background: silver;     font-size: 15px;      height: 55px

Explanation: Although PX is also a relative unit, due to the resolution hook, he actually becomes an absolute unit, natural flexibility is not high, but the use of low-level, and a large number of developers habitually use it.

3.% percent

{    margin: 0;     padding: 0;     background: silver;     font-size: 200%;      width: 50%

Explanation: A good understanding of length is the width of the block in which it is located. The font-size is the percentage of the original size that is inherited to.

4.CSS Unit of Measure

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.