CSS Vertical Centering Summary

Source: Internet
Author: User

Objective

Some summary of the vertical center layout, beginners can be used.

Element classification has been in the "CSS Horizontal Center Summary" in the said, here is not more to repeat.

One, single-line text vertical Center

Center vertically in a single line of text using the following method:

height:300px;

line-height:300px;

Second, the formal vertical center

1. Directly in the outer layer of the table vertical Center, simple and fast, this method applies to all elements . The disadvantage is that there are some non-semantic tags.

<table>
<tbody>
<tr>
<td>
<div>
I want to center vertically!
</div>
</td>
</tr>
</tbody>
</table>

2. Use CSS3 's flexbox for vertical centering, to write Display:flex and align-items:center in parent element , this method applies to all elements , but there is IE incompatible , the PC page is used with caution.

. father{
width:960px;
height:300px;
Background:yellow;
Display:flex;
Display:-webkit-flex;
Align-items:center;
-webkit-align-items:center;
}

Content continues to update in ...

Original article, hand play difficult, if you need to reprint please indicate the source . If there is a wrong place or a better way to use, I hope you can comment in the comments area, let us make progress together!

CSS Vertical Centering Summary

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.