【发布时间】:2015-02-02 03:46:53
【问题描述】:
我未能实现固定的表格布局。如果表格单元格包含的内容超出其容纳范围,则表格将重新布局,就像表格布局设置为自动一样。 这是HTML代码
<!DOCTYPE html>
<html>
<head>
<title>Table test</title>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="<path here>" />
</head>
<body>
<table>
<thead>
<tr>
<th class="number">Number</th>
<th class="name">Name</th>
<th class="type">Type</th>
<th class="comment">Comment</th>
<th class="buttons"></th>
</tr>
</thead>
<tbody>
<tr>
<td>42</td>
<td>This name is really long and is supposed to be truncated</td>
<td>Normal</td>
<td>I don't know what to say</td>
<td><button>Edit...</button></td>
</tr>
</tbody>
</table>
</body>
</html>
CSS 是
table {
border-collapse: collapse;
table-layout: fixed;
}
th {
font-weight: bold;
text-align: left;
}
td {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
tr {
border-top: 1px solid #000000;
border-bottom: 1px solid #000000;
}
th.number {
width: 6rem;
}
th.name {
width: 15rem;
}
th.type {
width: 17rem;
}
th.comment {
width: 15rem;
}
th.buttons {
width: 17rem;
}
这是fiddle。问题是第二列(“名称”)会增加,直到内容适合。我做错了什么?
【问题讨论】:
标签: html css html-table