Does a have to be inside a

后端 未结 5 1334
轻奢々
轻奢々 2021-01-04 21:22

Does a table row () have to be in a table body (), if the table has a table body, or can it exist outside of the table body?

5条回答
  •  生来不讨喜
    2021-01-04 21:59

    If you have a outside of a , the page will not validate: http://validator.w3.org

    As others have noted, is optional unless you're using or . The main reason to use the latter two elements is so the header and footer are repeated on each page if a long table is printed.

    It sounds like you might be creating something like a calendar, where you're wanting to have alternating rows of (e.g., for dates) and (e.g., for events on that date). If that's the case, you shouldn't wrap the alternating rows in and - doing so would confuse the heck out of browsers when it came to printing the page. If you just leave the grouping elements out, your table will validate. However, some screen readers might be confused by that markup and apply the top-most row of headers to all cells beneath them. For a complex table such as this, you'll need to add additional markup to assure that screen readers understand how the table is organized. Here's your table with accessible markup:

    ...
    ... ...
    ...
    ... ...

    Alternatively, you might want to consider whether the data can be organized in multiple tables, or if an alternative version can be provided that would be easier to use for screen reader users. For example, an events calendar could additionally be presented as a list of events.

提交回复
热议问题