Three ways to use vertical centering

Source: Internet
Author: User

Sometimes we need to center the contents of the element vertically, and here are three simple vertical centering methods I've learned

The first: Using the TD default Vertical-align:middle feature to achieve the vertical center effect of multiline text

Css:

  

    . Wrap{        width: 200px;         Height: 200px;         Border: 1px solid red;    }

Html:

    <table class= "wrap" > <tr> <td> Center content needs to center content needs to center content needs to center content need center content need center content            < td>        </tr>    </table>

Effect:

  

Second: single-line text setting with fixed height to container line-height equals container height to vertical center effect

Css:

    . Wrap{        width: 200px;         Height: 200px;         line-height: 200px;         Border: 1px solid red;    }

Html:

    <class= "wrap">         content        that needs to be centered </Div  >

Effect:

  Note: This method is valid only for single-line text

The third type: Use the new Display:table-cell to achieve vertical centering effect

Css:

    . Wrap{        width: 200px;         Height: 200px;         display: Table-cell;         vertical-align:Middle;         Border: 1px solid red;    }

Html:

    <class= "wrap"         >        Center content needs to be centered content Content        that needs to be centered </div>

Effect:

  

  Note: IE6 and IE7 do not support this CSS property value

Three ways to use vertical centering

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.