Most common way of writing a HTML table with vertical headers?

前端 未结 5 734
情话喂你
情话喂你 2020-12-04 11:04

Hi all it\'s been a while since I\'ve asked something, this is something that has been bothering me for a while, the question itself is in the title:

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 11:47

    First, your second option isn't quite valid HTML in the sense that all of the rows (TR) in a table should contain an equal number of columns (TD). Your header has 1 while the body has 3. You should use the colspan attribute to fix that.

    Reference: "The THEAD, TFOOT, and TBODY sections must contain the same number of columns." - Last paragraph of section 11.2.3.

    With that being said, the first option is the better approach in my opinion because it's readable regardless of whether or not I have CSS enabled. Some browsers (or search engine crawlers) don't do CSS and as such, it'll make your data make no sense as the header will then represent columns instead of rows.

提交回复
热议问题