【发布时间】:2016-02-13 12:57:02
【问题描述】:
在下面的代码中,我为表格单元格设置了max-width,因此无论它们携带的内容如何,它们都具有相同的宽度,并且vertical-align 设置为顶部。但是正如您所见,与第二个和第三个单元格相比,第一个单元格相当长,因此在第 2-5 个和第 3-6 个表格单元格之间留下了巨大的空间。有什么办法可以去掉那个空间吗?我的意思是我希望第 5 和第 6 个单元格立即跟随上述单元格,而不是等待第 1 个单元格结束。
table tr td {
vertical-align:top;
max-width:90px;
background-color: #dedede;
color: black
}
<table>
<tr>
<td>this is first cell. this will be quite lengthy</td>
<td>this is second cell</td>
<td>this is third cell</td>
</tr>
<tr>
<td>this is fouth cell</td>
<td>this is fifth cell</td>
<td>this is sixth cell</td>
</tr>
</table>
【问题讨论】:
-
我猜你在谈论类似Masonry
-
@dippas 是的,有 css 解决方案吗?
-
您可以使用浮动
<div>元素而不是表格单元格来获得这种效果。
标签: html css html-table tablecell