【发布时间】:2014-11-14 00:01:29
【问题描述】:
我正在尝试创建一个表格,其中流体列具有最小宽度。 所有其他列的宽度都是固定的,不应变宽或变薄。
我可以让流体列正确地增长和收缩,以便它占用容器中将最大宽度设置为 900 像素的剩余空间,但是我无法让它采用最小宽度。
这意味着当窗口和容器被压扁时,流体柱被覆盖,而不是此时表现得像固定柱。
对 th 和/或 td 应用最小宽度不会做任何事情。 对流体 td 内的 div 应用 min-wdith 确实意味着文本具有最小宽度,但是它不会阻止列缩小到小于此最小值,因此文本位于下一列文本的下方。
有什么想法吗?
HTML:
<div class="container">
<table>
<thead>
<tr>
<th class="fixed">fixed</th>
<th class="fixed">fixed</th>
<th class="fixed">fixed</th>
<th class="fluid">fluid</th>
<th class="fixed">fixed</th>
</tr>
</thead>
<tbody>
<tr>
<td>fixed</td>
<td>fixed</td>
<td>fixed</td>
<td class="fluid"><div align="left">Some text here which gets truncated, however should have min width</div></td>
<td>fixed</td>
</tr>
</tbody>
</table>
</div>
CSS:
.container {
max-width: 900px;
}
table {
table-layout: fixed;
width: 100%;
border: 1px solid #333;
border-collapse: separate;
border-spacing: 0;
}
th.fixed {
width: 100px;
}
th.fluid {
min-width: 100px;
}
td.fluid div {
width: auto;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
td.fluid {
background-color: #aaa;
min-width: 100px;
}
td {
background-color: #ddd;
border-right: 1px solid #333;
}
tr td {
text-align: center;
}
table th, table td {
border-top: 1px solid #333;
}
JSfiddle: http://jsfiddle.net/ajcfrz1g/14/
【问题讨论】:
-
设置表格的最小宽度以阻止其减小
标签: html css html-table fixed-width