Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么&x2019;s用于HTML的正确范围值<;th>;表格单元格是否跨越多个列?_Html_Html Table_Accessibility - Fatal编程技术网

什么&x2019;s用于HTML的正确范围值<;th>;表格单元格是否跨越多个列?

什么&x2019;s用于HTML的正确范围值<;th>;表格单元格是否跨越多个列?,html,html-table,accessibility,Html,Html Table,Accessibility,假设您有一个HTML表,其中有一个跨多个列的单元格,例如: <table> <tr> <th colspan="3" scope="?">Scores</th> <!-- ...more headings here... --> </tr> <tr> <th scope="col">English</th>

假设您有一个HTML表,其中有一个跨多个列的
单元格,例如:

<table>
    <tr>
        <th colspan="3" scope="?">Scores</th>
        <!-- ...more headings here... -->
    </tr>
    <tr>
        <th scope="col">English</th>
        <th scope="col">Maths</th>
        <th scope="col">Science</th>
        <!-- ...more sub-headings here... -->
    </tr>
    <tr>
        <td>12</td>
        <td>16</td>
        <td>20</td>
        <!-- ...more cells here... -->
    </tr>
</table>

分数
英语
数学
科学类
12
16
20

跨页眉单元格的scope属性的正确值是多少
col
似乎不正确,因为它的标题有好几列,但是如果我没有任何
colgroup
标记,则
colgroup
似乎不正确。

根据HTML规范中的第二个示例表,它是
colgroup
,尽管缺少
colgroup
标记

WebAIM(心中的Web易访问性)小组有一篇关于这方面的文章。总的来说,他们建议避免跨行或跨列,因为屏幕阅读器无法可靠地解释标记

除了完全避免跨列之外,我很幸运地将id/headers属性与scope属性结合使用。尽管标记更为详细,但这似乎简化了JAWS的工作,因此它在解释数据方面的困难更少

这是您的示例在id/标题下的样子:

<table>
    <tr>
        <th id="scores" colspan="3">Scores</th>
    </tr>
    <tr>
        <th id="english" scope="col">English</th>
        <th id="maths" scope="col">Maths</th>
        <th id="science" scope="col">Science</th>
    </tr>
    <tr>
        <td headers="scores english">12</td>
        <td headers="scores maths">16</td>
        <td headers="scores science">20</td>
    </tr>
</table>

分数
英语
数学
科学类
12
16
20

也许字幕功能更适合您

<table>
  <caption>Scores</caption>
  <thead>
    <tr>
      <th scope="col">English</th>
      <th scope="col">Maths</th>
      <th scope="col">Science</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>12</td>
      <td>16</td>
      <td>20</td>
    </tr>
  </tbody>
</table>

分数
英语
数学
科学类
12
16
20

好东西,谢谢。我倾向于支持规范的屏幕阅读器,而不是每个人都按照自己的怪癖编码,但是记录这些怪癖很好。啊,是的,很可能。我想到的实际用例是一个表,它的列比我的示例HTML中的多,因此跨多个列的标题实际上并没有跨整个表。我会相应地修改这个例子。明白了。戴夫使用身份证的反应似乎正是你想要的。你知道,4年前:)