gpt4 book ai didi

html - 在 HTML 表格中设置列宽

转载 作者:太空宇宙 更新时间:2023-11-04 16:12:03 25 4
gpt4 key购买 nike

目前,我有一张看起来像这样的 table

<table>
<tr>
<th>Submitted</th>
<th>Title</th>
<th>Revisions</th>
</tr>
<tr>
<td>Nov. 22, 2011, 2:14 a.m.</td>
<td><a href="/essays/edit/6">Hello</a></td>
<td>2</td>
</tr>
</table>

我需要 Title 列尽可能宽,而其他列刚好可以包含它们的内容。我还需要表格来填充其容器(100% 宽度)。
如何实现?

最佳答案

这可能是一种快速而肮脏的 hack,但您可以简单地使用以下 CSS:

td, th {
white-space: nowrap; /* to prevent splitting content into several lines */
}
th:nth-of-type(2) {
width: 100%;
}

表格内的单元格无法超过其总宽度,因此它可能会起作用。

或者,您可以使用 JavaScript 动态计算中间列宽或设置固定单元格宽度。

关于html - 在 HTML 表格中设置列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8223880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com