Home>Article>Web Front-end> What is the unit of CSS %?

What is the unit of CSS %?

藏色散人
藏色散人 Original
2021-01-05 10:27:28 2298browse

CSS % refers to percentage, which refers to a relative length unit, and the value is relative to the height, width or font size of the containing block; if an element has a percentage attribute set, the descendant elements will inherit it. is the calculated value.

What is the unit of CSS %?

The operating environment of this tutorial: Windows 7 system, css3 version, Dell G3 computer.

Related recommendations: "css video tutorial"

CSS %--Percent

Percent is a relative length unit, The value is relative to the height, width, or font size of the containing block.

The concept of containing block cannot simply be understood as the parent element.

If it is static positioning and relative positioning, the containing block is generally its parent element.

If it is an absolutely positioned element, the containing block should be the nearest ancestor element whose position is a non-static attribute.

If it is a fixed-positioned element, its containing block is the viewport.

For details, please refer to W3Help.

Inheritance of percentage

If an element sets the percentage attribute, the descendant elements inherit the calculated value. For example:

p { font-size: 10px;line-height: 120%; }

Then the value inherited by the sub-element of p is line-height: 12px, not line-height: 120%.

The above is the detailed content of What is the unit of CSS %?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn