我可以将一个 HTML 表格标题放在两个表格列上吗?喜欢 Excel 中的合并和居中吗?

StackOverflow https://stackoverflow.com/questions/8996466

我想让一个表格标题位于并排的两个表格列的中心。这可能吗?

有帮助吗?

解决方案

<th colspan="2">. This .</th>

外推...

<table>
  <thead>
    <tr>
      <th>Single Column</th>
      <th colspan="2">Double Column</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Column One</td>
      <td>Column Two</td>
      <td>Column Three</td>
    </tr>
  </tbody>
</table>
.

应该给你足够的工作。

其他提示

如果你只有 2 列那么我建议使用 <caption>. 。否则,请按照其他答案中的建议使用 colspan 。

<table>
  <caption>This will span all columns.</caption>
  <tr><td>column one</td><td>column two</td></tr>
</table>

当然。请参阅 页。您正在寻找名为的属性 colspan 对于表格标题单元格。

我们可以以更好的方式进行。

<table border="1"> 
  <tr>
    <th colspan="1" scope="colgroup">Test Heading</th>
    <th colspan="3" scope="colgroup">Mars</th>
    <th colspan="3" scope="colgroup">Venus</th>
    <th colspan="3" scope="colgroup">Test</th>
  </tr>
  <tr>
    <th rowspan="2"></th>
    <th scope="col">Produced</th>
    <th scope="col">Sold</th>
    <th scope="col">Sold</th>
    <th scope="col">Produced</th>
    <th scope="col">Sold</th>
    <th scope="col">Sold</th>
    <th scope="col">Test 1</th>
    <th scope="col">Test 2</th>
    <th scope="col">Test 3</th>
  </tr>
</table>
.

请访问表格ref如果您想了解更多。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top