Introduction to the Display:table-cell method for implementing DIV Vertical Center

Source: Internet
Author: User

IE7 and IE6 do not recognize Display:table-cell (but support css1 properties such as Display:block!)

IE8 and later versions can be identified!

IE7 and IE6 can identify vertical-align:middle;

If the box model has only a few paragraphs of text, set Line-height can be achieved center display!

If you want to center the Div in the box model, you can refer to the following code:

Div#wrap {

display:table;

border:1px solid #FF0099;

Background-color: #FFCCFF;

width:760px;

height:400px;

*position:relative;

Overflow:hidden;

}

Div#subwrap {

Vertical-align:middle;

Display:table-cell;

*position:absolute;

*top:50%;

}

div#content {

*position:relative;

*top:-50%;

}

Effect:

This is a multi browser compatible, but it has to be written several layers div~ but want to be in layer or IMG on the layer

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.