Vertical and Horizontal Headers in a table?

筅森魡賤 提交于 2019-12-05 15:10:26

问题


How would I get a table with both horizontal and vertical headers?

So e.g.

         header1 header2 header3 
header1    1        1      1
header2    2        2      2 
header3    3        3      3 

回答1:


Like @UlrichSchwarz said, you can just use <th> instead of <td> in the first column. Using scope, you can make it more semantically descriptive:

<table>
  <tr>
    <th></th>
    <th scope="col">header1</th>
    <th scope="col">header2</th>
    <th scope="col">header3</th>
  </tr>
  <tr>
    <th scope="row">header 1</th>
    <td>1</td>
    <td>1</td>
    <td>1</td>
  </tr>
  <tr>
    <th scope="row">header 2</th>
    <td>2</td>
    <td>2</td>
    <td>2</td>
  </tr>
  <tr>
    <th scope="row">header 3</th>
    <td>3</td>
    <td>3</td>
    <td>3</td>
  </tr>
</table>



回答2:


While you can still just <th> the entries in the first column, there is no column-equivalent of <thead>/<tbody> that I'm aware of.




回答3:


easy. Just leave the first td in the first tr - empty



来源:https://stackoverflow.com/questions/7354906/vertical-and-horizontal-headers-in-a-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!