【发布时间】:2015-02-04 22:37:42
【问题描述】:
我有一个表格,其中的列具有百分比宽度。如果这些单元格中的内容超过该百分比宽度,我希望将其截断为省略号。
根据CSS text-overflow in a table cell?,我应该使用 max-width 属性,但根据How can I set the max-width of a table cell using percentages?,我不能使用百分比。
table {
width: 100%;
}
table td {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
table tr td:nth-of-type(1) {
width: 20%;
}
table tr td:nth-of-type(2) {
width: 30%;
}
table tr td:nth-of-type(3) {
width: 50%;
}
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>
我该如何解决这个问题?
【问题讨论】:
-
你应该使用带有
column-count: 3;CSS3 Multiple Columns的div -
我不明白我为什么要这么做——它是一个包含表格数据的表格。