简体   繁体   English

带网格数据的HTML辅助功能

[英]HTML Accessibility with grid data

Here is a js fiddle of my example output: http://jsfiddle.net/Hdzv8/ and below is the html. 这是我的示例输出的js小提琴: http//jsfiddle.net/Hdzv8/ ,下面是html。 This is a pretty simple display of information but how would you make this accessible? 这是一个非常简单的信息显示,但是您如何使它可访问? I can make divs instead of tables but I cannot change the overall structure. 我可以制作div而不是表格,但我不能改变整体结构。 The problem I have is there currently is no indication that "Weight" is a header for "16oz". 我遇到的问题是目前没有迹象表明“重量”是“16oz”的标题。 How would you go about (from an accessability standpoint) labeling these sections as headers? 您将如何(从可访问性的角度)将这些部分标记为标题?

<table border="5">
<tr>
    <td colspan="6">Device Information</td>
</tr>
<tr>
    <td><b>Weight</b></td><td>16oz</td>
    <td><b>Height</b></td><td>3in</td>
    <td><b>Color</b></td><td>Brown</td>
</tr>
<tr>
    <td><b>Manufacturer</b></td><td>ACME Manufacturing</td>
    <td><b>Disposal Method</b></td><td>Shoot into the sun</td>
    <td><b>Alternate Color</b></td><td>Black</td>
</tr>
<tr>
    <td><b>Installation Manual</b></td><td>ACME 45.51.2009</td>
    <td><b>CCRC Code</b></td><td>CCRC551</td>
    <td><b>USNumber</b></td><td>55un</td>
</tr>

If you're going to have more than one record, I would leave this as a table (it's actually tabular data) but use th for the headers. 如果你将有一个以上的记录,我会把它作为一个表(它实际上是表格数据),但使用th作为标题。 If it's just the one record, I would go with div s or the like; 如果它只是一个记录,我会选择div等; seems more like presentation than just data then. 看起来更像是演示而不仅仅是数据。 HTMLDog has a few tutorials on tables with a lot of advice on usage and accessibility. HTMLDog有一些关于表的教程,其中包含大量有关使用和可访问性的建议。

Edit : On second thought, I might just make a two-column, nine-row table where each row designates a field (eg weight, height) and the first column uses th to specify the row header and the second column uses a td for the actual value. 编辑 :第二个想法,我可能只是制作一个两列九行表,其中每行指定一个字段(例如重量,高度),第一列使用th指定行标题,第二列使用td表示实际价值。 See this Fiddle for a working example. 有关工作示例,请参见此提琴

Edit 2 : This related SO post makes me think a definition or description list (using the dl tag) might be appropriate if you didn't want to use a table . 编辑2这个相关的SO帖子让我觉得如果你不想使用table定义或描述列表(使用dl标签)可能是合适的。

I don't know if this is possible with your real data (since I don't really see a clear column relation on your example) but you could also consider transforming the whole markup in one (or more) description list eg 我不知道你的真实数据是否可行(因为我没有真正看到你的例子中明确的列关系),但你也可以考虑在一个(或多个)描述列表中转换整个标记,例如

<tr>
   <td><b>Weight</b></td><td>16oz</td>
   ...
</tr>

could become 可能成为

<dl>
    <dt>Weight</dt><dd>16oz</dd>
    ...
</dl>

otherwise you can still use table with headers attribute like so 否则你仍然可以使用table with headers属性

<tr>
   <td id="header1"><b>Weight</b></td><td headers="header1">16oz</td>
   ...
</tr>

source: http://www.w3.org/TR/WCAG20-TECHS/H43 来源: http//www.w3.org/TR/WCAG20-TECHS/H43

If you have to keep that format, you don't need a table. 如果必须保留该格式,则不需要表格。 Tables should only be used for rendering data that belongs naturally in a grid. 表仅应用于呈现自然属于网格的数据。 If you have to keep this format you would be better off to use a description list instead and use CSS to style it into a bordered styled table. 如果你必须保持这种格式,最好使用描述列表,并使用CSS将其设置为带边框的样式表。

If you do use a table, here is the proper way. 如果您使用表格,这是正确的方法。 Use css instead of html attributes for styling Use 'strong' in place of 'b' Use tabl Tables must use proper html formatting 使用css而不是html属性进行样式使用'strong'代替'b'使用tabl表必须使用正确的html格式

<table class="myborderclass">
<caption>
Device Information
</caption>
<thead>
 <tr>
   <th scope="col">Weight</th>
   <th scope="col">Height</b></th>
   <td scope="col">Color</b></th>
   <th scope="col">Manufacturer</b></th>
   <th scope="col">Disposal Method</b></th>
   <th scope="col">Alternate Color</b></th>
   <th scope="col">Installation Manual</b></th>
   <th scope="col">CCRC Code</b></th>
   <th scope="col">USNumber</b></th>
 </tr>
</thead>
<tbody>
<tr>
   <td>16oz</td>
   <td>3 inches</td>
   <td>Brown</td>
   <td>ACME</td>
   <td>Shoot into the sun</td>
   <td>Black</td>
   <td>ACME 45.51.2009</td>
   <td>CCRC551</td>
   <td>55un</td>
  </tr>
 </tbody>
</table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM