繁体   English   中英

CSS表格单元格忽略宽度,即使表格已固定

[英]CSS table-cell ignores width, even with table-fixed

我想要一个带有display: table-celldiv display: table-cell设置了百分比宽度的display: table-cell display: table-cell是我最好的选择,我需要多个并排的div高度相等。

研究之后,我将父级设置为正确display: table; table-layout: fixed; width: 100% display: table; table-layout: fixed; width: 100% display: table; table-layout: fixed; width: 100%其他许多线程中发现的display: table; table-layout: fixed; width: 100% ,但table-cell仍填充父级。

 .table-wrapper { display: table; table-layout: fixed; width: 100%; } .table-cell { display: table-cell; width: 25%; overflow: hidden !important; border: 1px solid black; } 
 <div class="table-wrapper"> <div class="table-cell"> Should be 25%, but it fills .table-wrapper </div> </div> 

这不可能吗?

您可以使用单个block元素解决此问题。

 .table-wrapper { display: table; table-layout: fixed; width: 100%; border: 1px solid green; } .table-cell { display: table-cell; width: 25%; overflow: hidden !important; border: 1px solid black; } 
 <div class="table-wrapper"> <div class="table-cell"> Should be 25%, but it fills .table-wrapper </div> <div><div/> </div> 

标签总是会填满它,因为在每个...的末尾都有一个回车符。 但是,尽管如此。 因此,我建议使用没有回车符的标签。 希望能减轻一些挫败感...我不得不学习艰难的方法!

暂无
暂无

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

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