【发布时间】:2019-07-21 23:57:20
【问题描述】:
我有一个这样的 HTML 表格:
div {
width: 100%;
overflow-x: auto;
}
table {
white-space: nowrap;
}
td {
border: 1px solid gray;
padding: 5px 10px;
min-width: 100px;
max-width:40vw;
}
<div>
<table style="width: 100%;">
<tr>
<td class="block">1</td>
<td class="block">A table cell content</td>
<td class="block">This should be a text that breaks after 200px Lorem ipsum dolor sit amet</td>
<td class="block">A table cell content</td>
<td class="block">A table cell content</td>
<td class="block">A table cell content</td>
<td class="block">A table cell content</td>
</tr>
</table>
</div>
结果:
问题是,当到达max-width 时,文本应该换行。我知道white-space: nowrap 会导致这个问题,但如果没有,文本会在到达max-width 之前换行。
【问题讨论】:
标签: css html-table css-tables