当前,这意味着使用 HTML5。
而且,它应覆盖最广泛的人群,包括残障人士、老年人、文化水平不高或暂时患病的人以及喜欢只使用键盘或鼠标的人。
残障人士辅助功能旨在提供以下四个主要方面的解决方案:
- 听力
- 移动性
- 认知能力
- 视觉
这包括改写成文字的言语和符号语言(如果可能)。
不允许对页面进行任何自动刷新操作。
使用多个视觉提示和标准图标使内容易于理解。
在适用时使用 lang 属性和 abbr 标记。
这些属性一起构成了万维网联盟 (W3C) POUR 模型,它规定:显示给用户的信息和 UI 元素必须可被用户的感官感知;必须为用户提供操作 UI 的方式;用户必须可以理解信息和知道如何使用界面元素;内容必须足够稳健以便可以使用各种用户代理(包括辅助技术 (AT))来访问它。
既然您了解了辅助功能的基本知识,让我们看一下与易访问的 Web 设计有关的两个非常重要的概念: 逐渐增强和易访问的丰富 Internet 应用程序 (ARIA)。
逐渐增强和 ARIA
修改视觉效果内容(如黑体或斜体)的所有表示元素放入外部样式表。
如果忽略 CSS 文件(例如,通过屏幕阅读器),HTML 页面仍包含所有内容。
这类设备使用辅助功能 API 来访问网页。
图 1 用户如何使用辅助技术访问网页
bit.ly/b89BEJ。
让我们进一步了解 ARIA。
ARIA 角色
屏幕阅读器将知道此 HTML 元素用于导航,用户将能直接使用导航功能而非通过所有链接选择标签。
将 ARIA 角色属性应用到类似以下的 HTML 元素:
- <div role="XXX"> </div>
角色有以下三种类型:
- 作为导航界标的界标角色。
- 结构性角色定义文档的结构并帮助组织内容。
- 小组件角色由独立的 UI 小组件和复合小组件构成,其中复合小组件是两个或多个独立小组件的容器。
bit.ly/S0HUvi 中查看更多信息。
图 2 ARIA 角色值
| 界标角色 | 结构性角色 | 小组件角色 | |||
| 独立小组件 | 复合小组件 | ||||
| application | article | region | alert | progressbar | combobox |
| banner | columnheader | row | alertdialog | radio | grid |
| complementary | definition | rowheader | button | scrollbar | listbox |
| contentinfo | directory | separator | checkbox | slider | menu |
| form | document | toolbar | dialog | spinbutton | menubar |
| main | group | gridcell | status | radiogroup | |
| navigation | heading | link | tab | tablist | |
| search | img | log | tabpanel | tree | |
| list | marquee | textbox | treegrid | ||
| listitem | menuitem | timer | |||
| math | menuitemcheckbox | tooltip | |||
| note | menuitemradio | treeitem | |||
| presentation | option | ||||
与角色不同,ARIA 状态和属性是可为每个 HTML 元素设置的特性。
ARIA 状态
小组件状态是需要用户交互的 UI 小组件的属性。
以下显示了属性 aria-hidden:
- <div aria-hidden="true">
- <p>Paragraph text here </p>
- </div>
此代码将对屏幕阅读器隐藏该段落。
ARIA 属性
有 11 个全局属性和 14 个小组件属性(请参阅图 3)。
图 3 ARIA 状态和属性
| 属性类型 | 全局 | 小组件 |
| ARIA 状态 |
aria-busy aria-disabled aria-grabbed aria-hidden aria-invalid |
listitem math note presentation region row rowheader separator toolbar |
| ARIA 属性 |
aria-atomic aria-controls aria-describedby aria-dropeffect aria-flowto aria-haspopup aria-label aria-labelledby aria-live aria-owns aria-relevant |
aria-autocomplete aria-haspopup aria-label aria-level aria-multiline aria-multiselectable aria-orientation aria-readonly aria-required aria-sort aria-valuemax aria-valuemin aria-valuenow aria-valuetext |
以下是小组件属性 aria-required 的一个示例:
- <label for="username">User name:</label>
- <input id="username" type="text" aria-required="true">
这使表格的输入字段成为必填字段。
bit.ly/OlbLeh。
您了解一些 ARIA 及其角色、状态和属性后,就可以使用它来创建逐渐增强的易访问网站。
创建易访问的网站
让我们了解一下如何使用 HTML5 和 ARIA 创建以下每个组件,不要忘记实现辅助功能:
- 主页
-
带徽标的页眉区域
- 导航菜单
- 主图形
- 主内容
- 信息块
- 联系信息表
- “常见问题”页
- 带视频的“关于”页
图 4 显示我将创建的网站的基本结构。
图 4 网站示例的站点地图
为了创建它,我首先将 HTML5 用于实现逐渐增强,然后使网站可供 AT 设备访问。
图 5 主页的标准布局
正如您所看到的,我在页面上标识了很多元素: 页眉、导航、对操作的调用、主图形、包含简短内容的欢迎消息、信息块和页脚。
按照逐渐增强原则,我创建了一个按顺序的 HTML5 页来包含这些元素,使用了元素 <header>、<nav>、<figure>、<article>、<section>、<aside> 和 <footer>,如图 6 中所示。
图 6 HTML5 主页
- <!doctype html>
- <html lang="en">
- <head><title>HTML5 Home Page</title></head>
- <body>
- <header><!-- header -->
- <a href="/"><img src="images/logo.png"></a>
- </header>
- <nav><!-- navigation -->
- <ul>
- <li><a href="/">Home</a></li>
- <li><a href="/contact">Contact</a></li>
- <li><a href="/faq">FAQ</a></li>
- <li><a href="/about">About</a></li>
- </ul>
- </nav>
- <div><!-- main content -->
- <section>
- <figure><img src="images/maingraphics.png">
- <figcaption>Welcome image.
- More help on image<a href="#/">Help</a></figcaption>
- </figure>
- </section>
- <section>
- <h2><a href="Action" target="_blank">Subscribe</a></h2>
- <article>
- <h2>Welcome!</h2>
- <p><strong>Lorem Ipsum </strong>is simply dummy text of the printing and … </p>
- </article>
- </section>
- </div>
- <aside><!-- info blocks -->
- <h4>Promotion</h4><ul><li>items</li></ul>
- <h4>Awards</h4><ul><li>items</li></ul>
- <h4>News</h4><ul><li>items</li></ul>
- </aside>
- <footer><!-- footer -->
- <div>Copyright © 2012</div>
- <div><a href="">Privacy Policy</div>
- </footer>
- </body>
- </html>
例如,如果不支持 <header> 元素,浏览器将它替换为 <div>,如下所示:
- <header><!-- header -->
- <a href="/"><img src="images/logo.png"></a>
- </header>
- <div><!-- header -->
- <a href="/"><img src="images/logo.png"></a>
- </div>
为了使 AT 工具识别文档的导航界标和结构性部分,我为每个元素添加了以下角色,如图 7 中所示:
- header role=banner
- nav role=navigation
- maincontent role=main
- section role=region
- article role=article
- aside role=complementary
- footer role=contentinfo
图 7 添加角色
- <!doctype html>
- <html lang="en">
- <head><title> Accessible HTML5 Home Page</title></head>
- <body>
- <header role="banner"><!-- header -->
- <a href="/"><img src="images/logo.png"></a>
- </header>
- <nav role="navigation"><!-- navigation -->
- <ul>
- <li><a href="/">Home</a></li>
- <li><a href="/contact">Contact</a></li>
- <li><a href="/faq">FAQ</a></li>
- <li><a href="/about">About</a></li>
- </ul>
- </nav>
- <div id="maincontent" role="main"><!-- main content -->
- <section>
- <figure><img src="images/maingraphics.png">
- <figcaption>Welcome image.
- More help on image<a href="#/">Help</a></figcaption>
- </figure>
- </section>
- <section role="region">
- <h2><a href="Action" target="_blank">Subscribe</a></h2>
- <article role="article">
- <h2>Welcome!</h2>
- <p><strong>Lorem Ipsum </strong>is simply dummy text of the printing and … </p>
- </article>
- </section>
- </div>
- <aside role="complementary"><!-- info blocks -->
- <h4>Promotion</h4><ul><li>items</li></ul>
- <h4>Awards</h4><ul><li>items</li></ul>
- <h4>News</h4><ul><li>items</li></ul>
- </aside>
- <footer role="contentinfo"><!-- footer -->
- <div>Copyright © 2012</div>
- <div><a href="">Privacy Policy</div>
- </footer>
- </body>
- </html>
为了对所有浏览器应用样式,首先要将所有 HTML5 元素的块级元素放入样式表,如下所示:
- <style>
- header,footer,nav,article,aside,section,figure,figcaption{display:block;}
- </style>
我包含了 ARIA 角色以便为每个特定元素应用样式:
- <style>
- header[role="banner"]{/* Styles for banner */}
- header{/* Styles for other headers */}
- #maincontent[role="main"]{ /* Styles for main content */}
- nav[role="navigation"]{/* Styles for navigation */}
- section[role="group"]{/* Styles for section */}
- article[role="article"]{/* Styles for article */}
- aside[role="complementary"]{/* Styles for info blocks */}
- footer[role="contentinfo"]{/* Styles */}
- </style>
以下代码显示在我的示例中插入的脚本文件:
<div>Copyright © 2012</div>
</footer>
</body>
</html>
创建易访问的联系信息表
图 8列出与 HTML5 表格有关的输入类型和属性。
图 8 表格输入类型和属性
| 输入类型 |
input type=datetime input type=datetime-local input type=date input type=month input type=time input type=week input type=number |
input type=range input type=email input type=url input type=search input type=tel input type=color |
| 属性 |
autocomplete autofocus form formaction formenctype formmethod formnovalidate |
formtarget list multiple pattern placeholder required step |
这使得使用 AT 设备的人更易于访问它。
例如,input type=number 可以显示移动设备的数字键区,而 input type=url 则显示很多智能手机的虚拟键盘中的特殊“.com”按钮。
您将标签中的 for 属性与输入元素中的 id 属性一起使用,如下所示:
- <label for="useremail">Your E-mail:</label>
- <input id="useremail" name="useremail" type="email" value=""/>
例如,如果您有每个输入字段的一些帮助文本,可以将它与输入文本关联:
- <label for="useremail">Your E-mail:</label>
- <input id="useremail" type="email" value="" aria-describedby="helpemail"/>
- <p id="helpemail">Your email address will be used for further communication</p>
placeholder 属性允许您显示有效输入是什么样子,必需的属性则使输入框为必填字段:
- <label for="useremail">Your E-mail:</label>
- <input id="useremail" type="email" placeholder="john@msn.com" required
- aria-required="true" value="" aria-describedby="helpemail"/>
- <p id="helpemail">Your email address will be used for further communication</p>
请改用 aria-required 字段属性,它将告知 AT 设备该字段是必填字段并使用背景色或图像(而非星号)将这点告知用户。
您还可以添加 autofocus 属性,它帮助将焦点设置为表格的第一个元素。
图 9 显示用于创建一个易访问的 HTML5 联系信息表的代码,图 10 则显示联系信息表。
图 9 创建一个 HTML5 联系信息表
- <div id="contact" role="main"><!-- main content -->
- <!-- content -->
- <section id="content">
- <article>
- <h2>Contact <span>Form</span></h2>
- <form id="contacts-form" action="" method="post">
- <fieldset>
- <div class="field">
- <label for="name" >Name </label>
- <input id="name" placeholder="John Smith" autofocus required
- aria-required="true" type="text" value="" />
- </div>
- <div class="field">
- <label for="email">E-mail</label>
- <input id="email" placeholder="john@msn.com" type="email" required
- aria-required="true" value=""/>
- </div>
- <div class="field">
- <label for="website">Website</label>
- <input id="website" placeholder="http://website.com"
- type="url" />
- </div>
- <div class="field">
- <label for="message">Message</label>
- <textarea id="message"
- placeholder="Write your message Here!" required
- aria-required="true" ></textarea>
- </div>
- <div><a href="#" onclick="submit()">Send Your Message!</a></div>
- </fieldset>
- </form>
- </article>
- </section>
- </div>
图 10 浏览器中的“联系信息表”页
执行更新可能对残障人士有一定困难,但是当您将 aria-live 属性与 status、log 和 alert 的角色属性一起使用时,活动区域可使辅助设备识别更新:
- aria-live=“off”: 未公布更新(区域为非活动的)
- aria-live=“polite”: 用户空闲时公布更新
- aria-live=“assertive”: 优先级更高,但是更新不一定立即公布
- 用于不同消息类型的 role=“log”、role=“status” 和 role=“alert”
以下是将此集成到 HTML 代码的一个简单方法:
- <div id="liveregion" role="log" aria-live="polite">
现在我们来看具有易访问内容的“常见问题”页。
使用图像创建易访问的“常见问题”页
因此,不采用:
- <i>italics</i>
您使用:
- <em>emphasized</em>
- <cite>citation</cite>
不采用:
- <b>bold</b>
您使用:
- <strong>strong</strong>
例如,一些屏幕阅读器将更改 <strong> 元素的音调但不更改 <b> 元素的音调。
图 11 给出了一个示例。
图 11“常见问题”页的标记
- <h1>FAQ</h1>
- <h2>List of frequently asked questions</h2>
- <ul>
- <li><a href="#q1">Accessible Text</a></li>
- <li><a href="#q2">Accessible Tables</a></li>
- <li><a href="#q3">Accessible Links</a></li>
- <li><a href="#q4">Accessible Images</a></li>
- <li><a href="#q5">Accessible Titles</a></li>
- </ul>
- <h2 id="q1">Accessible Text</h2>
- <h3>Semantic HTML</h3>
- <h3>Proper hierarchy</h3>
- <h3>Localized content</h3>
- <h3>Acronym</h3>
- <h3>Font-size</h3>
- <h3>Color</h3>
- <h2 id="q2">Accessible Table</h2>
- <h2 id="q3">Accessible Links</h2>
- <h2 id="q4">Accessible Images</h2>
- <h2 id="q5">Accessible Titles</h2>
要创建本地化的内容,您使用全局 <html> 元素中的 lang 属性设置页面的语言:
- <html lang="en">
对于采用不同语言的内容,请在 <p> 或 <span> 元素中使用 lang,如下所示:
- <p><span lang="la">Carpe diem </span>(seize the day)</p>
并对缩写形式使用 abbr 标记:
- <p>The <abbr title="World Wide Web Consortium">W3C</abbr> was founded in 1994.</p>
使用以下值之一来增加或减小浏览器默认的字体大小:
- 百分比 (%)
- em(相对于大写字母 M 的大小)
- ex(相对于大写字母 X 的大小)
- 关键字(小、中、大、更小、更大等)
例如:
- font-size:100%;
- line-height:1.125em;
W3C 建议普通文本的对比率为 4.5 比 1,更大文本的对比率为 3 比 1。
确保您对同一信息有多个提示,如用标签指示错误。
例如:
- body {
- font-family:Arial, Helvetica, sans-serif;
- font-size:100%;
- line-height:1.125em;
- background-color:#212222;
- color:#242424;
- }
不过 HTML5 提供了很多有用的新标记:
- <caption> 是表的标题
- <details> 显示用户可以按需查看或隐藏的其他详细信息
- <summary> 在屏幕阅读器读取真实表数据前公布
- <thead> 指示表头行
- <tfoot> 指示表尾行
图 12 显示易于 AT 设备访问的示例 HTML 表的代码。
图 12 易访问的表
- <h4>Table with Caption, Summary and Details</h4>
- <table>
- <caption>
- <strong>Lorem Ipsum.</strong>
- <details>
- <summary>Help</summary>
- <p><strong>Lorem Ipsum </strong>is simply dummy text of the printing and </p>
- </details>
- </caption>
- <thead>
- <tr>
- <th>Table header column 1</th>
- <th>Table header column 2</th>
- <th>Table header column 3</th>
- </tr>
- </thead>
- <tfoot>
- <tr>
- <td>Table footer column 1</td>
- <td>Table footer column 2</td>
- <td>Table footer column 3</td>
- </tr>
- </tfoot>
- <tbody>
- <tr>
- <td>Table data column 1</td>
- <td>Table data column 2</td>
- <td>Table data column 3</td>
- </tr>
- </tbody>
- </table>
下面是添加链接的正确方式:
- <p>Designandmethod.com has an article on accessibility.
- See the <a title="click for more information at the Design & Method Web site" href="http://designandmethod.com">Big picture at Design and Method</a></p>
如果您的设计需要“>”,请使用 CSS 背景图像。
您可以在样式表中使用修饰做到这点:
- {
- text-decoration: underline;
- display:block;
- border-bottom:1px solid #000;
- }
如果 alt 和 title 属性均未找到,AT 设备将公布图像的名称,因此请确保为图像指定有意义的名称。
使带动画的图像最小化;它们可能导致癫痫病人发病。
以下示例显示如何使图像易访问:
- <figure><img src="images/maingraphics.png" alt="Example screen shot" title="main graphics showing screenshot example"><figcaption>Image with caption.</figcaption></figure>
以下是用于图像映射的代码:
- <area shape=rect coords=0,0,10,10 href="example.htm" alt="example">
在开头具有简明的标题和相关关键字可以帮助视力受损的用户更快地浏览它们。
在标题开头使用精确、相关的关键字可提高内容的易访问性:
- <a href="#q1"><!--How to make content Accessible-->Accessible Content</a>
- <a href="#q2"><!--How to make links Accessible-->Accessible Links</a>
- <a href="#q3"><!--How to make images Accessible-->Accessible Image</a>
- <a href="#q4"><!--How to make titles Accessible-->Accessible Titles</a>
我们先了解如何使音频和视频元素易访问。
具有音频和视频的易访问“关于”页
以下是一些使音频和视频内容易访问的方法:
- 以 HTML 格式提供音频或视频的文字记录。
- 对于不支持 media 标记的浏览器提供替代内容。
- 控件至少要有“开”/“关”按钮。
- 媒体不应是自动启动而是用户启动的。
- 提供下载媒体文件的链接。
- 使用视频/音频磁迹提供字幕(隐藏字幕或字幕)。
对于耳聋用户,字幕是更好的解决方案,因为它们不包含伴随所说话语的噪声、音响效果、音乐等。
现在我们可以使用 track 元素和以下格式提供字幕支持:
- WebVTT 用于为视频内容加字幕
- SMPTE-TT(计时的文本格式)用于加字幕
- SRT 用于字幕文件
请注意对视频的辅助功能支持仍在继续改进,但是以下提供了一个示例:
- <video controls>
- <source src="video-file.mp4" type="video/mp4"/>
- <track src="en.vtt" kind="subtitles" srclang="en"
- label="English p subtitles" default/>
- <track src="en.ttml" kind="captions" srclang="en"
- label="English p captions" default/>
- </video>
这些控件可通过键盘访问:
- 空格键用于切换播放和暂停。
- 左箭头和右箭头分别用于将视频前进和后退 5 秒。
- CTRL+左箭头或右箭头分别用于将视频前进或后退 60 秒。
- HOME+左箭头或右箭头用于跳到视频的开头或结尾。
- 如果音量按钮有焦点,则上箭头和下箭头可以增加和减小音量。
Visual Studio 2012 中的辅助功能支持
现在提供 HTML 元素中 ARIA 角色、特性和属性的 IntelliSense,如图 13 和图 14 中所示。
图 13 Visual Studio 2012 中对 ARIA 角色的 IntelliSense 支持
图 14 IntelliSense 中支持 ARIA 属性
使用 Visual Studio 2012,您可以轻松通过右键单击某个页面并选择“检查辅助功能”这样做,如图 15 中所示。
图 15 您可以在 Visual Studio 2012 中检查网页的辅助功能
您选择了准则后,Visual Studio 2012 将检查所有 HTML 元素并显示有关页面中任何错误或警告的详细报告,如图 16 中所示。
图 16 Visual Studio 2012 中的 Web 内容辅助功能报告
当您浏览易访问的 Web 内容时这些应是工具箱中的有用附加工具。
iRajLal.com。
Chava 和 Dennis Lembrée