Mobile development: Several CSS unit attributes that you may not know ., Css Unit

Source: Internet
Author: User
Tags vmin

Mobile development: Several CSS unit attributes that you may not know ., Css Unit

1. rem

The "em" unit is commonly used in development. It indicates to set the size of the current element based on the unit size of the parent element of the current element; in "rem", "r" represents "root", which indicates to set the unit size of the current element based on the unit size of the root (that is, "html") element, therefore, no matter whether the current element is any subnode, once the unit size is set to "rem", the size of this element is based on the root element unit, both "em" and "rem" Here are inherited.

2. vw and VL (mobile development is my favorite unit attribute, which is also the focus of this introduction)

In traditional responsive development, we often use percentages for layout, but this is not the best solution. For example, you cannot set the percentage with the height of the body.

The full name of "vw" is "viewport width", that is, the width of the window; "Vl" is "viewport height", that is, the height of the window.

1vw = viewportWidth * 1/100; 1vl = viewportHeight * 1/100;

Therefore, the element uses "vw" and "Vl" as the width and height units, which ensures that the elements are compatible with different devices.

3. vmin and vmax

"Vmin" refers to the one with the smallest width and height of "viewport. (That is, if the current element unit is set to "vmin", the browser will determine the width and height, and then inherit small values)

Similarly, "vmax" inherits the value that is larger than width and height. That is, the value that is inherited when the width and height are greater.

Assume that the browser width is 1300px and the height is 960px;

50 vmin = 960*(50/100 );
50 vmax = 1300*(50/100 );

4. ex and ch

These two units are rarely used in our daily development. We will not elaborate on them here. The following figure explains the meaning of these two units. If you are interested, you can check the information yourself.

 

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.