CSS tutorial: line-height inheritance

Source: Internet
Author: User

Line-height, which is frequently seen in tutorials at www.bkjia.com, contains many little-known things. The line-height value can be: <length >|< percentage >|< number> | noromal | inherit. Both em, px, and percentage are calculated relative to the font-size value of the element. However, when a block-level element inherits the line-height attribute of another element, the situation becomes more complex. When the line-height value is inherited from the parent element, it must be calculated from the parent element rather than the child element.

Reference content is as follows:
<Body style = "font-size: 10px;">
<Div style = "line-height: 150%">
<P style = "font-size: 15px;"> gfire is a global provider of Chinese Internet information and tutorials. It has been insisting on providing impetus for Internet development for many years, liehuo is passionate, positive, upward, and progressive. the character advocated by Net! </P>
</Div>
</Body>

Here, the font-size of p is 16px, but the line-height inherited by p is only 15px, so the row gets closer. Solution: 1. You can explicitly set the line-height attribute for each element, but it is not practical.

2. specify a number to set the scaling factor.

Reference content is as follows:
<Body style = "font-size: 10px;">
<Div style = "line-height: 1.5">
<P style = "font-size: 15px;"> gfire is a global provider of Chinese Internet information and tutorials. It has been insisting on providing impetus for Internet development for many years, liehuo is passionate, positive, upward, and progressive. the character advocated by Net!
</P>
</Div>
</Body>

When a number is specified, the zoom factor inherits the value instead of the calculated value. This number applies to this element and all its child elements, so each element can calculate line-height based on its own font-size value. So the line-height of p here is 15 * 1.5px;

Related Article

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.