Html html表格单元格组合

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4477927/
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 05:46:33  来源:igfitidea点击:

html table cells combine

htmlcsshtml-table

提问by Alex Pliutau

I have a table with 3 rows and 3 columns. How can combine last row columns? My html:

我有一个 3 行 3 列的表格。如何组合最后一行列?我的html:

<table>
  <tr><td></td><td></td><td></td></tr>
  <tr><td></td><td></td><td></td></tr>
  <tr><td>Here I need a cell by all width</td></tr>
</table>

回答by Oded

Use the colspanattribute:

使用colspan属性:

<tr><td colspan="3">Here I need a cell by all width</td></tr>

The colspan attribute defines the number of columns a cell should span.

colspan 属性定义了一个单元格应该跨越的列数。

There is a related attribute rowspanthat achieves the same for rows.

有一个相关的属性rowspan可以实现相同的行。

回答by Alin Purcaru

For this exact purpose the colspanattribute was created.

正是出于这个目的,colspan创建了该属性。

<table>
  <tr><td></td><td></td><td></td></tr>
  <tr><td></td><td></td><td></td></tr>
  <tr><td colspan="3">Here I need a cell by all width</td></tr>
</table>

Similarly you can use use the rowspanattribute if you want to span multiple rows.

同样,rowspan如果您想跨越多行,您可以使用该属性。

<table>
  <tr><td></td><td></td><td rowspan="3">Spans full table height</td></tr>
  <tr><td></td><td></td></tr>
  <tr><td></td><td></td></tr>
</table>

To learn more about these two attributes visit the official documentation on w3.org.

要了解有关这两个属性的更多信息,请访问w3.org 上的官方文档

Also I urge you not to use tables unless you need to present tabular data.

此外,我敦促您不要使用表格,除非您需要提供表格数据。