【发布时间】:2015-09-05 14:14:53
【问题描述】:
将表格单元格中的max-width 设置为 250 像素会自相矛盾地阻止单元格(列)在表格宽度发生变化时小于 250 像素。同时,最大宽度似乎根本没有受到限制。
...为什么?
小提琴:
查看实际操作:http://jsfiddle.net/cehjc8m6/1/
HTML:
<table>
<tr>
<td>Left col</td>
<td class="ell">
This is a rather long text. It should be truncateed when it
exceeds the available horizontal space.
</td>
<td>Right col</td>
</tr>
</table>
CSS:
table {
width: 500px; // change this value to see the effect
}
td {
white-space: nowrap;
}
td.ell {
overflow: hidden;
text-overflow: ellipsis;
max-width: 250px;
}
【问题讨论】:
-
也许当你表格的东西它只能处理一个宽度元素?
-
max-width仅适用于块级元素 -
@APAD1 你是对的。所以需要使用
display: inline-block;。
标签: html css html-table