简体   繁体   中英

Make table-cell 100% width of parent

How would I make the table-cell 100% width of the parent.

It works perfectly fine when the text is long enough to reach the full width of the element but when the text is not it doesn't want to center whilst using table-cell and vertical-align: middle;

Here is a fiddle:

https://jsfiddle.net/DTcHh/7471/

Update:

Here's a better solution using a flex-box:

jsFiddle

h4 {
    height: 50px;
    font-size: 1em;
    width: 100%;
    font-style: oblique;
    color: #FFF;
    text-align: center;
    margin-left: 5px;
    display: flex;
    justify-content: center; /* align horizontal */
    align-items: center; /* align vertical */
   }

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