Vertical-align and line-height ),

Source: Internet
Author: User

Vertical-align and line-height ),

Method 1: vertical-align

W3school definition: This attribute defines the vertical alignment of the baseline of an element in a row relative to the baseline of the row where the element is located

Best friend

Then Google. No definition is found on w3schools.

Only code can be written for testing

And then I understand it before I make such an explanation.

The object to which this attribute applies: the inline element (inline, inline-block also has the row attribute) and other table-cell

Common attribute values: top middle bottom

Personal Understanding



In my opinion, in general, the line that these letters spontaneously "sit" is the baseline. The distance between the two rows is line-height (the second method will be used later). It is unclear how to align the baseline after top middle bottom is set.

This is the result of testing top middle bottom.



Method 2: Use line-height

In the block element, set line-height to be the same as the height to vertically center the element in the row. Note that the most direct way to use the unit of the row height is to use px. If the percentage is used, for example, if 150% is used, 150% is calculated based on the font size of the parent element, and the child element still follows the calculated Row Height. If 1.5 is used, the row height is calculated by multiplying the font size of the child element by 1.5. In addition, 1.5em and so on are calculated according to the 150% case.


For more information about the two methods, see "I think ".



Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.