简体   繁体   中英

vertical-align middle not working on table-cell

请检查http://jsfiddle.net/4Ly4B/我已经vertical-align: middle table-cell中的中间位置不会居中

An element with display:table-cell ignores min-width and min-height . You have to use height and width instead.
Also, if you want to position the element using position:absolute , you wrap the element in a container, and assign position:absolute to this container.

See this fiddle: http://jsfiddle.net/4Ly4B/3/

The property vertical-align doesn't work with min-height . Remove min-height and add padding instead of it.

.message{
    background-color: gray;
    position: absolute;
    padding-top: 40px;
    padding-bottom: 40px;
    min-width: 200px;
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

vertical-align: middle; it's basicall used for table-cell.in your example position is absolute this way u can do this

.message{
background-color: gray;
position: absolute;
min-width: 200px;
display: table-cell;
padding:60px 0px 60px 0px;
text-align: center;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM