如何标记表格的水平和垂直轴?

时间:2019-03-09 00:29:12

标签: html

假设您有一个表格,其中垂直轴是高度,水平轴是重量,并且表格单元格是对应的BMI。您如何标记垂直轴“ Height”和水平轴“ Weight”?

<table>
  <thead>
    <tr>
      <th></th>
      <th>140 lbs</th>
      <th>150 lbs</th>
      <th>160 lbs</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>5'4</th>
      <td>24</td>
      <td>25.7</td>
      <td>27.5</td>
    </tr>
    <tr>
      <th>5'6</th>
      <td>22.6</td>
      <td>24.2</td>
      <td>25.8</td>
    </tr>
    <tr>
      <th>5'8</th>
      <td>21.3</td>
      <td>22.8</td>
      <td>24.3</td>
    </tr>
  </tbody>
</table>

1 个答案:

答案 0 :(得分:1)

您要使用colspan和rowspan合并单元格。如果可以帮助您了解最终表的外观,请尝试在excel中绘制表。在excel中,您必须合并单元才能完成相同的事情。

<table>
  <thead>
    <tr>
      <th colspan="4">Weight</th>
    </tr>
    <tr>
      <th></th>
      <th>140 lbs</th>
      <th>150 lbs</th>
      <th>160 lbs</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th rowspan="4">Height</th>
    </tr>
    <tr>
      <th>5'4</th>
      <td>24</td>
      <td>25.7</td>
      <td>27.5</td>
    </tr>
    <tr>
      <th>5'6</th>
      <td>22.6</td>
      <td>24.2</td>
      <td>25.8</td>
    </tr>
    <tr>
      <th>5'8</th>
      <td>21.3</td>
      <td>22.8</td>
      <td>24.3</td>
    </tr>
  </tbody>
</table>