HTML 表格 - 固定和多个可变列宽

标签 html css html-table multiple-columns

我必须构建一个包含 5 列的表。表格宽度是可变的(内容宽度的 50%)。一些列包含固定大小的按钮,因此这些列应该有一个固定大小,比如 100px。有些列中包含文本,因此我希望这些列具有可变的列宽。

例如:

第 1 列:(tablewidth - sum(fixedwidth_columns)) 的 20%

第 2 列:100px

第 3 列:(tablewidth - sum(fixedwidth_columns)) 的 40%

第 4 列:200px

第 5 列:(tablewidth - sum(fixedwidth_columns)) 的 40%

实现此目标的最佳方法是什么?

最佳答案

您可以设置 table-layout: fixed 对于 table元素,然后简单地设置 width相关属性 <td><th>元素:

table {
    table-layout: fixed;
}

JSFiddle Demo .

来自MDN :

The table-layout CSS property defines the algorithm to be used to layout the table cells, rows, and columns.

值(value)观:

fixed:
Table and column widths are set by the widths of table and col elements or by the width of the first row of cells. Cells in subsequent rows do not affect column widths.

关于HTML 表格 - 固定和多个可变列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21651767/

相关文章:

jquery - 如何将值传递给 JQUery 回调方法?

html - 表格响应式布局 CSS/HTML

php - 用于 CSS 表单测试的填充 URL

html - 省略 </TD> 和 </TR> 标签是否安全?

html - 滚动条聚焦在 HTML div 的底部

html - CSS - 平滑扩展按钮宽度并在悬停时显示文本

javascript - 附有 JS 效果的 CSS 动画类型阻塞/阻塞英雄图像

css - Font Awesome 图标不显示

javascript - 在这种特殊情况下,indexOf 匹配变量

php - URL 末尾的正斜杠会破坏 CSS