ヘッダー属性を使用する表のセルは、同じ表内のセルのみを参照する必要があります。
修正方法
この問題を解決するには、 headers
テーブルを使用する各セルが同じテーブル内の別のセルを参照するように、 scope
要素内の th
要素ごとに tr
属性値を作成します。このルールは、ヘッダー列と行への参照が特定の td
要素に接続されているかどうかをチェックします。
scope
属性は、列の下のすべてが上部のヘッダーに関連し、行ヘッダーの右側のすべてがそのヘッダーに関連することをブラウザーとスクリーンリーダーに伝えます。
scope属性をテーブルに適用すると、マークアップは次のようになります。
例
<table>
<caption><strong>Greensprings Running Club Personal Bests</strong></caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">1 mile</th>
<th scope="col">5 km</th>
<th scope="col">10 km</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Mary</th>
<td>8:32</td>
<td>28:04</td>
<td>1:01:16</td>
</tr>
<tr>
<th scope="row">Betsy</th>
<td>7:43</td>
<td>26:47</td>
<td>55:38</td>
</tr>
<tr>
<th scope="row">Matt</th>
<td>7:55</td>
<td>27:29</td>
<td>57:04</td>
</tr>
<tr>
<th scope="row">Todd</th>
<td>7:01</td>
<td>24:21</td>
<td>50:35</td>
</tr>
</tbody>
</table>
Name、1マイル、5 km、10 kmの上部ヘッダーはすべて th
要素でマークアップされており、Mary、Betsy、Matt、Toddの行ヘッダーも同様であることに注意してください。これらの各ヘッダー セルには、列ヘッダー セルか行ヘッダー セルかに応じて、 scope
属性値 col
または row
も与えられています。
colgroup
属性と rowgroup
属性の値 scope
を使用することです、ヘッダー セルをデータ セルに関連付けるもう1つの方法は。このマークアップ手法は、複数の列または行にまたがるヘッダーを示すために使用されます。MozillaのLearn HTML Developer Docsにある次の表を検討してください。
服 | アクセサリー | |||||
---|---|---|---|---|---|---|
ズボン | スカート | ドレス | ブレスレット | リング | ||
ベルギー | アントワープ | 56 | 22 | 43 | 72 | 23 |
ゲント | 46 | 18 | 50 | 61 | 15 | |
ブリュッセル | 51 | 27 | 38 | 69 | 28 | |
オランダ | アムステルダム | 89 | 34 | 69 | 85 | 38 |
ユトレヒト | 80 | 12 | 43 | 36 | 19 |
scope="colgroup"
要素におよび scope="rowgroup"
の値を含める例 th
<table>
<caption>Items Sold August 2016</caption>
<tbody>
<tr>
<td></td>
<td></td>
<th colspan="3" scope="colgroup">Clothes</th>
<th colspan="2" scope="colgroup">Accessories</th>
</tr>
<tr>
<td></td>
<td></td>
<th scope="col">Trousers</th>
<th scope="col">Skirts</th>
<th scope="col">Dresses</th>
<th scope="col">Bracelets</th>
<th scope="col">Rings</th>
</tr>
<tr>
<th rowspan="3" scope="rowgroup">Belgium</th>
<th scope="row">Antwerp</th>
<td>56</td>
<td>22</td>
<td>43</td>
<td>72</td>
<td>23</td>
</tr>
<tr>
<th scope="row">Gent</th>
<td>46</td>
<td>18</td>
<td>50</td>
<td>61</td>
<td>15</td>
</tr>
<tr>
<th scope="row">Brussels</th>
<td>51</td>
<td>27</td>
<td>38</td>
<td>69</td>
<td>28</td>
</tr>
<tr>
<th rowspan="2" scope="rowgroup">The Netherlands</th>
<th scope="row">Amsterdam</th>
<td>89</td>
<td>34</td>
<td>69</td>
<td>85</td>
<td>38</td>
</tr>
<tr>
<th scope="row">Utrecht</th>
<td>80</td>
<td>12</td>
<td>43</td>
<td>36</td>
<td>19</td>
</tr>
</tbody>
</table>
なぜ重要なのか
スクリーン リーダーには、テーブルを読み上げるための特別な方法があります。テーブルが適切にマークアップされていない場合、スクリーン リーダーの出力が混乱したり不正確になったりする可能性があります。
目の見えるユーザーは、通常、テーブルのヘッダーが何であるか、データとの関係が何であるかを一目で知ることができます。目の見えないユーザーの場合、これはマークアップで行う必要があります。
データ テーブルがアクセシビリティを考慮して設計されている場合、ユーザーはテーブル ナビゲーション モードに入り、スクリーン リーダーがデータ セルに対応するテーブル ヘッダーを読み上げながら、テーブル内のセル間を移動できます。テーブルヘッダーを読むと、大きなデータテーブル間を移動する場合や、セルに似ていて混同しやすいデータが含まれている場合に特に役立ちます。
ただし、テーブルにアクセシビリティ機能がない場合、テーブルナビゲーションモードは役に立ちません。
ルールの説明
データ テーブルのマークアップは面倒でわかりにくいです。テーブルを意味的に、正しいヘッダー構造でマークアップしてください。スクリーン リーダーにはテーブル ナビゲーションを容易にする機能がありますが、これらの機能が正しく動作するにはテーブルを正確にマークアップする必要があります。
仕組みについて (簡単に言うと)
データ テーブルが意味的にマークアップされ、正しいヘッダー構造を持っていることを確認します。