Html HTML5 - 如何为特定单元格指定固定宽度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15284606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 06:14:10  来源:igfitidea点击:

HTML5 - How can I specify a fixed width for a particular cell?

csshtml

提问by Hosea146

In HTML5, how can I specify a fixed width for a table cell? Most of the <col>properties which were available in HTML4 are no longer valid in HTML5.

在 HTML5 中,如何为表格单元格指定固定宽度?<col>HTML4 中可用的大多数属性在 HTML5 中不再有效。

Just to be clear, I know I can do <td style="width:150px">, but this does not keep the column width fixed. No matter what the contents of the cell are, I want the width fixed at 150px.

为了清楚起见,我知道我可以做到<td style="width:150px">,但这并不能保持列宽固定。无论单元格的内容是什么,我都希望宽度固定为 150px。

采纳答案by Explosion Pills

You can use widthon col. Depending upon what you are doing it may also be helpful to use a fixed width child of the <td>to enforce its width as this does not work by setting the width of <td>alone due to its table-celldisplay type.

您可以widthcol. 根据您在做什么,使用 的固定宽度子项<td>来强制其宽度也可能会有所帮助,<td>因为由于其table-cell显示类型,这不能通过单独设置宽度来工作。

http://jsfiddle.net/ywSvr/

http://jsfiddle.net/ywSvr/

回答by Blair Anderson

Use colgroup

colgroup

<table>
  <colgroup>
     <col span="1" style="width: 15%;">
     <col span="1" style="width: 70%;">
     <col span="1" style="width: 15%;">
  </colgroup>
  <thead></thead>
  <tbody></tbody>
</table>

回答by FelipeAls

Use the othertable algorithm by adding table-layout: fixed:

通过添加使用其他表算法table-layout: fixed