html - html table -- 设置列以占用剩余空间,并且至少 300px 宽度
问题描述
如何在 html 表格中间创建一列,并使其填充剩余空间,同时最小宽度为 300px?
HTML:
<table>
<tr>
<td class="fixed-width">A set width column</td>
<td class="remaining-width-or-300-pixels">
A column with long content, to take the remaining space, and at least 300 pixels. It's OK if it has to trucate.
</td>
<td class="fixed-width">A set width column</td>
</tr>
</table>
CSS:
table {
display: table;
width: 100%;
table-layout: fixed;
white-space: nowrap;
color: white;
}
table td {
overflow: hidden;
}
td.fixed-width {
background: blue;
width: 200px;
}
td.remaining-width-or-300-pixels {
background: red;
overflow: hidden;
min-width: 300px;
}
如您所见,当您调整面板的宽度时,min-width: 300px;
完全被忽略了。
我可以采用任何 css (不是 javascript)解决方法来使其正常工作吗?
编辑:另外,任何使用
div
元素而不是table
,tr
和td
元素的解决方案都不起作用,我正在使用一个需要使用table
元素的库。
解决方案
我认为问题在于table-layout: fixed;
根据这里,固定的值将设置一个固定的表格布局算法。表格和列的宽度由 table 和 col 的宽度或第一行单元格的宽度设置。可能是最小宽度不适用于 td 的原因。
table {
display: table;
width: 100%;
/* table-layout: fixed; */
white-space: nowrap;
color: white;
}
table td {
overflow: hidden;
}
td.fixed-width {
background: blue;
width: 200px;
min-width: 200px;
}
td.remaining-width-or-300-pixels {
background: red;
overflow: hidden;
min-width: 300px;
}
<table>
<tr>
<td class="fixed-width">A set width column</td>
<td class="remaining-width-or-300-pixels">
A column
</td>
<td class="fixed-width">A set width column</td>
</tr>
</table>
推荐阅读
- memory - 如何使用另一个程序访问一个程序的堆空间?
- flutter - Dart 中相对导入的正确代码样式是什么?
- python - 无法让 python 在 Visual Studio 代码上正常工作
- visual-studio - 文件夹中的新文件会自动添加到 TFS (TFVC) 挂起的更改中吗?
- javascript - 在溢出div的水平滚动上,填充进度条
- cordova - 即使设置了 httpMethod,cordova-plugin-file-transfer 上传也显示为 GET 请求
- django - 访问调用 celery 任务时传递的额外数据
- python - Python beautifulsoup:删除元素中的特定元素
- qt - QML:如何在 RowAlignment 中均匀分布?
- javascript - CSS / Javascript动画高度为具有不同高度的项目展开和折叠