我想显示 4 或 5 个框(不同),它们占据 100% 的页面宽度,因此它将跨越页面的开始到结束。并希望高度刚好适合内容。
我正在尝试为此使用表格,因此它将为每个框分配宽度并填满整行。
下面代码的问题是 td 中的所有 div 都居中并且高度不同。尝试了所有我能想到的但它不起作用。尝试垂直对齐,高度为 100% .....
如何让 td 中的所有 div 具有相同的高度?
此外,如果还有其他方法可以做到这一点,请告诉我。我是 html 虚拟人,所以可能没有使用正确的东西。
<table style="width: 100%; text-align:justify;">
<tr>
<td>
<div style="margin-right:15px; background-color:Gray">
Some text here
</div>
</td>
<td>
<div style="margin-right: 15px; background-color:Gray">
column 2 text here
</div>
</td>
<td>
<div style="margin-right: 15px; background-color:Gray">
Column 3 text here
</div>
</td>
<td>
<div style="background-color:Gray">
Last column text here
</div>
</td>
</tr>
</table>
最佳答案
就像我告诉很多其他人的那样,您不应该在表格单元格内使用分隔符。
这将实现完全相同的效果,但没有除法:
<table style="width: 100%; text-align: justify;">
<tr>
<td style="margin-right: 15px; background-color: gray;">
Some text here
</td>
<td style="margin-right: 15px; background-color: gray;">
column 2 text here
</td>
<td style="margin-right: 15px; background-color: gray;">
Column 3 text here
</td>
<td style="background-color: gray;">
Last column text here
</td>
</tr>
</table>
关于html表格如何使所有列的高度相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2412420/