【问题标题】:Tables and Screen Readers表格和屏幕阅读器
【发布时间】:2014-02-05 19:18:47
【问题描述】:

我似乎无法让屏幕阅读器阅读简单的表格。我有下面的 HTML:

<table alt="Account Information">
       <tr>
          <th scope='row'>Account Number:</th>
          <td>1111 1111 1111</td>
          <td>&nbsp&nbsp<td/>
          <th scope='row'>Reference Number:</th>
          <td>XXXX XXXX XXXX</td>
       </tr>
</table>

当屏幕阅读器点击此表时,它会显示 “表。0 列。0 行。”

我在网上尝试了很多示例,并尝试使用 WCAG2.0 标准作为指导方针,但似乎不起作用。

我也尝试了不同的表格布局和结构,但仍然得到相同的结果。

【问题讨论】:

  • 您的标头和数据彼此相邻是否有特定原因?
  • @ShashankChaturvedi 它们是行标题而不是列标题
  • 这意味着单行,因为你只有一行。
  • 是的,这就是信息必须显示的方式
  • 您是否尝试过用在线示例替换您的表格,看看是否可行?我读到单元格不应该为空,所以我建议删除第三个单元格并添加 css 来处理空格。我还读到表描述可以在打开表标记之后的&lt;caption&gt; 标记中,而不是在 alt 中。我怀疑这会影响读者,但从有效的标记开始,然后逐渐建立,直到你得到你的结果。只是一个猜测,但可能是你的读者很不稳定。

标签: html screen accessibility wcag2.0


【解决方案1】:

我没有通过屏幕阅读器运行它,但它可能会被您的&amp;nbsp 抛弃。 &amp;nbsp 需要用分号关闭。像这样:&amp;nbsp;。此外,表没有 alt 属性。提供对屏幕阅读器有用的解释,改用summary attribute

除此之外,我建议您删除那个空单元格并使用 CSS 腾出更大的空间。

1 - 删除空白行并用 CSS 提供一个间隙,如下所示:

HTML

<table summary="Account Information">
   <tr>
      <th scope="row">Account Number:</th>
      <td>1111 1111 1111</td>

      <th scope="row">Reference Number:</th>
      <td>XXXX XXXX XXXX</td>
   </tr>
</table>

CSS

th { padding: 0 10px;  }

2 - ...除此之外,也许它有点挑剔,所以你可以试试:

<table summary="Account Information">
    <thead>
        <tr>
            <th scope="col">Account Number Heading</th>
            <th scope="col">Account Number</th>
            <th scope="col">Reference Number Heading</th>
            <th scope="col">Reference Number</th>
        </tr>
    </thead>

    <tbody>
        <tr>
            <th scope="row">Account Number:</th>
            <td>1111 1111 1111</td>

            <th scope="row">Reference Number:</th>
            <td>XXXX XXXX XXXX</td>
        </tr>
    </tbody>
</table>

CSS

thead { display: none; }
th { padding: 0 10px;  }

3 - ...但理想情况下,表格应该是这样的:

<table summary="Account Information">
    <thead>
        <tr>
            <th scope="col">Account Number</th>
            <th scope="col">Reference Number</th>
        </tr>
    </thead>

    <tbody>
        <tr>
            <td>1111 1111 1111</td>
            <td>XXXX XXXX XXXX</td>
        </tr>
    </tbody>
</table>

CSS

th { padding: 0 10px;  }

【讨论】:

  • 我也打算建议添加tbody,至少可以提一下!
  • @SaggingRufus 这些示例中的任何一个对您有用吗?
  • 最后一个例子是你所说的理想例子:) 只是一件事.. table 元素没有 alt 属性,但你可以使用 summary 属性来汇总数据并使用 @ 987654332@ 元素来描述表格的内容。
  • 添加thead 然后用display:none 隐藏它有点没有意义(示例2),因为屏幕阅读器不会宣布它。
猜你喜欢
  • 2016-09-23
  • 1970-01-01
  • 1970-01-01
  • 2016-11-11
  • 2015-08-16
  • 2019-05-16
  • 1970-01-01
  • 1970-01-01
  • 2017-11-10
相关资源
最近更新 更多