Html 将表格列合并为单个单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4904639/
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
Merging table column into single cell
提问by zmol
I have a table that looks like this and this is its markup
我有一个看起来像这样的表,这是它的标记
______________________
_____|_______|________
_____|_______|________
<table>
<tbody>
<tr>
<td>row 1 column 1</td>
<td>row 1 column 2</td>
<td>row 1 column 3</td>
</tr>
<tr>
<td>row 2 column 1</td>
<td>row 2 column 2</td>
<td>row 2 column 3</td>
</tr>
</tbody>
</table>
How can I merge the entire second column into 1 cell so the table looks like this. Is it possible?
如何将整个第二列合并为 1 个单元格,使表格看起来像这样。是否可以?
_____________________________
________| |_________
________|__________|_________
回答by Matt Eskridge
<table>
<tbody>
<tr>
<td>row 1 column 1</td>
<td rowspan="2">row 1 column 2</td>
<td>row 1 column 3</td>
</tr>
<tr>
<td>row 2 column 1</td>
<td>row 2 column 3</td>
</tr>
</tbody>
</table>
This should work. Any element with rowspan="2" will span two rows. you can also put colspan="2" to span columns.
这应该有效。任何具有 rowspan="2" 的元素都将跨越两行。您还可以将 colspan="2" 用于跨列。
回答by Sean
add a rowspan="2" to the second td of the first row and remove the second td from the second row.
将 rowspan="2" 添加到第一行的第二个 td 并从第二行中删除第二个 td。