英文:
HTML Table: Multiple header rows and column
问题
需要类似以下的HTML结构:
这是我的代码:
<table>
<tr>
<th colspan="2">第一行</th>
</tr>
<tr>
<th colspan="3">第二行1</th>
<th colspan="3">第二行2</th>
</tr>
<tr>
<th>第二行1.1</th>
<th>第二行1.2</th>
<th>第二行1.3</th>
<th>第二行2.1</th>
<th>第二行2.2</th>
<th>第二行2.3</th>
</tr>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
<td>e</td>
<td>f</td>
</tr>
</table>
然而,我得到的结果如下:
我应该怎么办?
英文:
I need something like this in HTML
please click here for the layout
This is my code:
<table>
<tr>
<th colspan="2">ROW A</th>
</tr>
<tr>
<th colspan="3">ROW B1</th>
<th colspan="3">ROW B2</th>
</tr>
<tr>
<th>RB1.1</th>
<th>RB1.2</th>
<th>RB1.3</th>
<th>RB2.1</th>
<th>RB2.2</th>
<th>RB2.3</th>
</tr>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
<td>e</td>
<td>f</td>
</tr>
</table>
However, this is what I get:
What am I supposed to do?
答案1
得分: 3
你只需要将"ROW A" 更改为以下内容:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<th colspan="6">ROW A</th>
<!-- end snippet -->
列数由表格中具有最多列数的行决定。在这种情况下,表格中任何行的列数最多为6。如果你希望"ROW A" 的宽度与表格相同,你需要设置colspan为6。如果你希望它的宽度是表格宽度的一半,你需要设置colspan为3。
英文:
You only need to change "ROW A" to this :
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<th colspan="6">ROW A</th>
<!-- end snippet -->
The number of columns is determined by the amount of columns in the row that has the most.
In this case, the highest number of columns of any row of the table is 6. If you want "ROW A" to be as wide as the table, you need a colspan of 6. If you want it to be half the width of the table, you would need a colspan of 3.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论