CSS Vertical centering Method (ii)

Source: Internet
Author: User

The fourth method:

This method sets the display of some div as a table, so we can use the Vartial-align property of the table.

The code is as follows:

<!DOCTYPE HTML><HTMLLang= "en"><Head>  <MetaCharSet= "UTF-8">  <title>Document</title>  <styletype= "Text/css"> #wrapper  {  display:  table; }#cell{Height:300px;//If the height is not set, the effect is not obvious and appears to be not centered, but is actually centered in the wrapper.Background-color:Yellow;Display:Table-cell;vertical-align:Middle;}. Content{Height:100px;//plus height is to show more obviousBackground-color:Red;}  </style></Head><Body>    <DivID= "wrapper">        <DivID= "Cell">        <Divclass= "Content">Diveeeeeeeeeeeeeeeeeeeeeeeeeeeeeuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu Uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuueeeeeeeeeeeee</Div>      </Div>    </Div></Body></HTML>

Advantages:

    • Content can dynamically change height. Content is not truncated when there is not enough space in the wrapper

Disadvantages:

    • Not valid in Internet Explorer (even IE8 beta), many nested tags

The display results are as follows:

CSS Vertical centering Method (ii)

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.