CSS Unit Learning

Source: Internet
Author: User

1、emThe unit is defined as the current font size. For example, if you body set a font size on an element, the body value of any child element within the element is em equal to the font size.

In the body nested three-layer Div, to the outermost div through the class property to set the font size of 16px, and then set the font size for all div elements of 2em.

:

2, "" in the "" " rem r root ; This is equivalent to font-size setting based on the root element; In most cases, the root element is the html element. REM is achieved by scaling based on a unique standard.

:

You can also set the width and height by a unique standard: Width:70rem;

3. VH and VW

Responsive web design technology relies heavily on proportional rules. However, the CSS scale is not always the best solution for each problem. The CSS width is relative to the nearest containing parent element. What if you want to use the width or height of the display window instead of the width of the parent element? This is exactly what the vh vw unit has to offer.

Use vw to set a font size. This size will be scaled proportionally to the width of the browser.

vhEqual to viewport height 1/100 . For example, if the browser is high 900px , the 1vh value evaluated is 9px . Similarly, if the display window width is 750px , the 1vw value to be evaluated is 7.5px .

div{
FONT-SIZE:25VW;
}
4, Vmin and Vmax

vhAnd vm is always related to the height and width of the viewport, unlike, vmin and vmax is related to the maximum or minimum value of this width and height, depending on which is larger and smaller. For example, if the browser 1100px is set to wide and 700px high, it 1vmin will be 7px , 1vmax for 11px . However, if the width is set to and the height is set to, it will be equal to and will be 800px 1080px 1vmin 8px 1vmax 10.8px .

Copyright belongs to the author.
Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
Original: Https://www.w3cplus.com/css/7-css-units-you-might-not-know-about.html? W3cplus.com

CSS Unit Learning

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.