HTML 表格不同行中不同的列数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3838488/
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
HTML Table different number of columns in different rows
提问by Harsha M V
Like in Excel sheet can I have
就像在 Excel 表中一样,我可以拥有
- 2 columns in 1st row
- 1 long column in the 2nd row
- 第一行 2 列
- 第 2 行中的 1 个长列
is this possible in html ?
这在 html 中可能吗?
回答by David says reinstate Monica
On the realisation that you're unfamiliar with colspan
, I presumed you're also unfamiliar with rowspan
, so I thought I'd throw that in for free.
意识到你不熟悉colspan
,我认为你也不熟悉rowspan
,所以我想我会免费把它扔进去。
One important point to note, when using rowspan
: the following tr
elements mustcontain fewer td
elements, because of the cells using rowspan
in the previous row (or previous rows).
需要注意的一点是,使用时rowspan
:以下tr
元素必须包含较少的td
元素,因为rowspan
在前一行(或前几行)中使用了单元格。
table {
border: 1px solid #000;
border-collapse: collapse;
}
th,
td {
border: 1px solid #000;
}
<table>
<thead>
<tr>
<th colspan="2">Column one and two</th>
<th>Column three</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2" colspan="2">A large cell</td>
<td>a smaller cell</td>
</tr>
<tr>
<!-- note that this row only has _one_ td, since the preceding row
takes up some of this row -->
<td>Another small cell</td>
</tr>
</tbody>
</table>
回答by Nivas
Colspan:
科尔斯潘:
<table>
<tr>
<td> Row 1 Col 1</td>
<td> Row 1 Col 2</td>
</tr>
<tr>
<td colspan=2> Row 2 Long Col</td>
</tr>
</table>