[英]Setting column width in HTML 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%)。
如何做到這一點?
這可能是一個快速而骯臟的技巧,但是您可以簡單地使用以下CSS:
td, th {
white-space: nowrap; /* to prevent splitting content into several lines */
}
th:nth-of-type(2) {
width: 100%;
}
表格中的單元格不可能超過其整體寬度,因此它可能會起作用。
或者,您可以使用JavaScript動態計算中間列的寬度或設置固定的單元格寬度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.