【发布时间】:2020-06-05 05:18:41
【问题描述】:
在下面的示例中,我希望单元格在到达max-width 之前不换行。这仍然会导致表格溢出,这是我想要的行为。
main {
max-width: 600px;
overflow: hidden;
}
th {
background: #ccc;
padding: 2px 5px;
white-space: nowrap;
max-width: 120px;
}
<main>
<table>
<tr>
<th>One</th>
<th>One Two</th>
<th>One Two Three</th>
<th>Four</th>
<th>Five</th>
<th>Six</th>
<th>Seven</th>
<th>Seven Eight</th>
<th>Seven Eight Nine</th>
<th>Seven Eight Nine Ten</th>
</tr>
</table>
</main>
【问题讨论】:
-
1) 你在说哪个
max-width?600或120。 2) 如果max-width是600,那么如果你只是在溢出时包装内容,你认为使用nowrap有什么意义吗?请更清楚地解释您的问题,因为在目前的表格中,它的描述非常糟糕,并且是一篇低质量的帖子。 -
120的thmax-width。我希望th单元格的行为类似于nowrap,直到它们达到120的宽度,此时我希望它们换行。 -
也许我直到现在才完全理解这个问题,但是当我们删除 th 选择器的“空白:nowrap”时,我看到了预期的行为(据我所知) . th-cells 会根据文本的数量进行扩展,直到它们达到 120px 宽度。然后文本开始换行,th-width 为 120px。我在这里误会了什么?
标签: css html-table width nowrap