简体   繁体   English

如何使用 JavaScript、CSS 或 HTML 将键盘导航(辅助功能访问)添加到现有网站?

[英]How to add Keyboard navigation( Accessibility Access) to existing website using JavaScript, CSS or HTML?

How to add Keyboard navigation to an existing website using JavaScript, CSS, or HTML?如何使用 JavaScript、CSS 或 HTML 将键盘导航添加到现有网站? I don't want to add any paid apps.我不想添加任何付费应用程序。 if you know free javascript library or something let me know.如果您知道免费的 javascript 图书馆或其他信息,请告诉我。

similar techs I used: tabindex="0", a:focus{border: solid 2px blue}我使用的类似技术:tabindex="0", a:focus{border: solid 2px blue}

Some concrete advice:一些具体的建议:

Use standard HTML5 elements where possible.尽可能使用标准的 HTML5 元素。 Read up on HTML5 semantics, in particular headings and navigation.阅读 HTML5 语义,特别是标题和导航。 Before reaching for custom classes and CSS display/visibility features, make use of HTML attributes like hidden and disabled to control the visibility and availability of content and UI.在达到自定义类和 CSS 显示/可见性功能之前,使用 HTML 属性(如hiddendisabled )来控制内容和 UI 的可见性和可用性。

By all means use <div> and <span> elements for presentation and layout, but pay attention to document structure.一定要使用<div><span>元素进行展示和布局,但要注意文档结构。 Let semantic markup reflect/express the meaning you intend.语义标记反映/表达您想要的意思。 ARIA landmark roles can help, although most of them are implicit in HTML already. ARIA 地标角色可以提供帮助,尽管其中大部分已经隐含在 HTML 中。

Note that the "Outline algorithm" mentioned in the HTML5 spec is not implemented on any browser, so don't get too hung up on perfectly sequential heading levels, just be consistent and logical.请注意,HTML5 规范中提到的“大纲算法”并未在任何浏览器上实现,因此不要过于关注完美连续的标题级别,只要保持一致和合乎逻辑即可。 I find that starting each landmark with a new <h1> tends to be easiest to manage, but others prefer to have only one <h1> per page (thereafter starting distinctly meaningful areas or landmarks with <h2> ).我发现以新的<h1>开始每个地标往往最容易管理,但其他人更喜欢每页只有一个<h1> (此后以<h2>开始明显有意义的区域或地标)。 Both approaches are acceptable, and the exact choice should depend on complexity and did I mention consistency?这两种方法都是可以接受的,确切的选择应该取决于复杂性,我有没有提到一致性?

Add ARIA attributes sparingly, and only when HTML does not already express the intended semantic.谨慎添加ARIA 属性,仅当 HTML 尚未表达预期语义时才添加。 (eg adding aria-pressed to a <button> turns it into a toggle button). (例如,将aria-pressed添加到<button>会将其变成切换按钮)。 No need to add aria-disabled="true" if the element already has a HTML5 disabled attribute.如果元素已经具有 HTML5 disabled属性,则无需添加aria-disabled="true"

It's worth knowing that ARIA attributes work well in CSS attribute selectors .值得一提的是,ARIA 属性在CSS 属性选择器中运行良好。 If you use them, you can style your content based on their values, which keeps things synchronised.如果你使用它们,你可以根据它们的值来设计你的内容,这样可以保持同步。

Ensure that all operable/interactive elements are clearly labeled using standard HTML mechanisms like <label> if possible.确保所有可操作/交互元素都使用标准 HTML 机制(如可能)清楚地标记<label> If a visible label is not desired, or is ambiguous without visual cues, you may use aria-label to provide an 'offscreen' one.如果不需要可见的 label,或者在没有视觉提示的情况下模棱两可,您可以使用aria-label来提供“屏幕外”。

More complex interactions may need some special keyboard handling in javascript.更复杂的交互可能需要在 javascript 中进行一些特殊的键盘处理

Pay attention to the many articles offering guidance about color and contrast (for users with low-vision or color blindness).请注意许多提供有关颜色和对比度指导的文章(针对视力不佳或色盲的用户)。 In particular, make sure the keyboard focus indicator is always clear and obvious.尤其要确保键盘焦点指示器始终清晰明显。 (You mentioned the CSS outline property in your question, so you are on the right track). (您在问题中提到了 CSS outline属性,所以您走在正确的轨道上)。

Provide text alternatives for all non-decorative images.为所有非装饰性图像提供替代文本。 If you're using an <img> tag, the alt attribute works very well.如果您使用的是<img>标签,则alt属性效果很好。 Decorative images need this too, but with a null value.装饰图像也需要这个,但具有 null 值。 (eg alt="" ) (例如alt=""

Bear in mind different screen sizes and orientations.请记住不同的屏幕尺寸和方向。 Consider using responsive CSS features such as media queries, grid and flex layouts.考虑使用响应式 CSS 功能,例如媒体查询、网格和弹性布局。 Avoid re-ordering content visually when it contradicts the meaning of the sequence in the underlying HTML code.当内容与底层 HTML 代码中序列的含义相矛盾时,请避免以视觉方式重新排序内容。

Consider that users may want to increase text size or line spacing using custom settings.考虑到用户可能希望使用自定义设置来增加文本大小或行间距。 This means leaning on relative units such as % , em and rem , rather than px , which should be reserved for hairline borders, or media query breakpoints.这意味着依赖于相对单位,如%emrem ,而不是px ,它应该为细线边界或媒体查询断点保留。

VALIDATE YOUR CODE using an HTML validator.使用 HTML 验证器验证您的代码。 Free dev tools such as axe-core will also give very useful feedback and helpful guidance.免费的开发工具,如axe-core也会提供非常有用的反馈和有用的指导。

Use stack overflow for concrete questions.针对具体问题使用堆栈溢出。 It's pretty reliable.这很可靠。 Many good accessibility questions have already been asked and answered.已经提出并回答了许多良好的可访问性问题。 Search first!先搜索!

If you follow this advice, and if your product is not too outlandish in design, you will most likely be able to approach a high level of conformance with WCAG A/AA without too much pain.如果您遵循这个建议,并且您的产品在设计上不是太古怪,您将很可能能够在没有太多痛苦的情况下接近 WCAG A/AA 的高水平一致性。

Finally: Transparency is more important than full conformance.最后:透明度比完全符合更重要。 If you have WCAG violations you can't fix in the current iteration, be open and honest about it, and you will be in the clear, legally speaking.如果您有无法在当前迭代中修复的 WCAG 违规行为,请坦诚相待,从法律上讲,您将一清二楚。 Perfect conformance is rare, and especially so for a first time accessibility implementation.完美的一致性是罕见的,尤其是对于第一次可访问性的实现。 Welcome to this challenging and rewarding field, and good luck!欢迎来到这个充满挑战和回报的领域,祝你好运!

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

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