The advantage of not setting a unit in line height line-height:1.8

Source: Internet
Author: User

Today inadvertently saw the line-height:1.8 feel quite interesting, and then turned down the high knowledge, found also quite an article, may be warm so know new.

First look at the following: Top line, midline, Baseline, bottom line

The vertical-align is the vertical alignment of the elements, and also depends on the lines, which have top (top line alignment), middle (centerline alignment), Baseline (baseline alignment), bottom (bottom line alignment), respectively.

Line spacing and row height (the distance between the baseline of a line of text):

In order to make it more convenient to measure the high value of the line, I usually choose the text bottom to the text bottom this way to measure, and the height is the same.

===================================================================================

So what's the use of line-height:1.8 this?

The row height is inheritable, but the computed value is inherited, such as:

<Divstyle= "background: #ddd; height:100px;line-height:180%;font-size:15px;">                <Pstyle= "font-size:30px">Chinese 中文版<BR/>Chinese 中文版</P></Div>

Here div's Row height is 180%*15px=27px

and the line height of p is calculated 27px instead of 180%*30px=54px

From the above example we know that the gap between the text is not only the height of the decision, but also affected by the font size,

If you inherit a computed value, it may cause the font to overlap when the text font size in the element is different.

To avoid this, you can define a value that does not have a unit as the scaling factor to uniformly control the row height, and the scaling factor is inherited directly, not the computed value:

<Divstyle= "background: #ddd; height:100px; line-height:1.8; font-size:15px; ">                <Pstyle= "font-size:30px;">Chinese 中文版<BR/>Chinese 中文版</P></Div>

The P-line height here is 1.8x30px=54px, which means the effect is the same as the following code.

<Divstyle= "background: #ddd; height:100px;font-size:15px;">                <Pstyle= "font-size:30px; line-height:54px">Chinese 中文版<BR/>Chinese 中文版</P></Div>

The advantage of not setting a unit in line height line-height:1.8

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.