在行之间使用多个标头编码HTML表的最佳方法是什么?
在行之间使用多个标头编码HTML表的最佳方法是什么?我创建了一个不错的HTML表。但是,当我尝试将屏幕读取器用于508合规性时,屏幕读取器读取所有行标题(标题1,标头2,标头3)时,当我浏览每行时。有没有办法避免它?我想念什么?
这是小提琴:
https://jsfiddle.net/kq739m28/
<p>Test</p>
<div style=" overflow-x: auto;">
<table style=" width: 100%;">
<thead>
<tr>
<td> </td>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
<th>8</th>
<th>9</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="10" scope="colgroup" style=" background-color: #e0e0e0; text-align: left;">Header1</th>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">dffddf</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td> </td>
<td> </td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">fdfdfdf</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">dffddf</th>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td>✓</td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
</tr>
<tr>
<th colspan="10" scope="colgroup" style=" background-color: #e0e0e0; text-align: left;">Header2</th>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">5455445</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">fdfggfgf</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th colspan="10" scope="colgroup" style=" background-color: #e0e0e0; text-align: left;">Header3</th>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">fgggf</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td> </td>
<td>✓</td>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">fgggfgf</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td> </td>
<td> </td>
<td>✓</td>
<td> </td>
</tr>
</table>
</div>
What is the best way to code HTML table with multiple headers in between rows? I have created a decent HTML table. However, when I try to use the screen reader for 508 compliance, the screen reader reads all row headers (Header 1, Header 2, header 3) when I navigate through each row. Is there a way to avoid it? What am I missing?
Here is the fiddle:
https://jsfiddle.net/kq739m28/
<p>Test</p>
<div style=" overflow-x: auto;">
<table style=" width: 100%;">
<thead>
<tr>
<td> </td>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
<th>8</th>
<th>9</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="10" scope="colgroup" style=" background-color: #e0e0e0; text-align: left;">Header1</th>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">dffddf</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td> </td>
<td> </td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">fdfdfdf</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">dffddf</th>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td>✓</td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
</tr>
<tr>
<th colspan="10" scope="colgroup" style=" background-color: #e0e0e0; text-align: left;">Header2</th>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">5455445</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td align="center" style=" text-align: center; color: black;"> </td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">fdfggfgf</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th colspan="10" scope="colgroup" style=" background-color: #e0e0e0; text-align: left;">Header3</th>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">fgggf</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td> </td>
<td>✓</td>
</tr>
<tr>
<th style=" font-weight: 400; text-align: left;">fgggfgf</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td> </td>
<td> </td>
<td>✓</td>
<td> </td>
</tr>
</table>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用ARIA
roun =“ RowGroup”
属性属性&lt; tbody&gt; 元素来指定标头行必须应用的行。然后,您还应将scope =“ RowGroup”应用于您的单个标头行。
例如:
我用JAWS 2022和NVDA 2021在Chrome 99中测试了此代码,以确保每次我从列到列移动时都不会宣布所有行标头。
这是一些有用的文章,解释了如何实现ARIA
rowGroup
角色:W3C技术:使用范围属性将数据表中的标头单元和数据单元关联
mdn web文档:aria:rowgroup crom
You'll need to use the ARIA
role="rowgroup"
attribute on separate<tbody>
elements to specify the group of rows to which the header row must apply. Then you should also apply thescope="rowgroup"
attribute to your individual header rows.For example:
I tested this code in Chrome 99 with JAWS 2022 and NVDA 2021 to make sure that the screen reader wasn't announcing all row headers each time I moved from column to column.
Here are some useful articles explaining how to implement the ARIA
rowgroup
role:W3C Techniques for WCAG 2.1: Using the scope attribute to associate header cells and data cells in data tables
MDN Web Docs: ARIA: rowgroup role
您可以使屏幕阅读器跳过它。
You can make the screen reader skip it.