简体   繁体   English

使表格单元格为父级的100%宽度

[英]Make table-cell 100% width of parent

How would I make the table-cell 100% width of the parent. 我将如何使表格单元格为父级的100%宽度。

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; 当文本足够长以达到元素的整个宽度时,它可以很好地工作;但是当文本不是足够长时,它不希望在使用table-cell和vertical-align时居中。

Here is a fiddle:

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

Update: 更新:

Here's a better solution using a flex-box: 这是使用弹性盒的更好解决方案:

jsFiddle 的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 */
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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