当名称属性已过时HTML5如何跳过导航

编程入门 行业动态 更新时间:2024-10-27 19:26:26
本文介绍了当名称属性已过时HTML5如何跳过导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Web内容可访问性指南中指出,您应该提供一个跳过链接,用于跳过(例如)导航块并直接进入内容。这对于使用屏幕阅读器以可听的方式描述页面的受损用户尤其有用。

6.2分组和绕过链接 WCAG指南

然而,这种技术依赖于使用name属性在标签上:

< h2>< a name =content>内容< / a>< / H2>

随着跳转链接:

< a href =#content>跳至内容< / a>

问题是,锚定标记的name属性在HTML5中已过时。 HTML过时功能

有没有其他方法可以在不使用name属性的情况下实现这个跳转到功能?

脚注:HTML5规范仍处于草稿状态,它是在这种情况下名称属性可能会继续被允许 - 尽管它可能仍然会产生一个警告。它目前被标记为过时但符合,这意味着您仍然可以使用它 - 但是,我想知道其他方式执行跳转到,看看是否有办法做到这一点, t依赖于过时的属性。

解决方案

不是使用< a> 标签,您可以使用具有 id 属性的任何元素:

< h2 id =content>内容< / h2> < a href =#content>跳至内容< / a>

编辑,找到了您的源代码(尽管它是维基百科; - )):

或者(有时并发),使用name或id属性设置,该元素成为目标。统一资源定位器可以通过片段标识符链接到此目标。 现在可以通过使用id属性[2]将任何元素制作为锚点,因此不需要使用< a name =foo> 。

en.wikipedia/wiki/HTML_element#Anchor

In the Web Content Accessibility Guidelines is states that you should supply a "skip" link that jumps you (for example) over a navigation block and straight into the content. This is particularly useful for impaired users who use a screen-reader to describe a page audibly.

6.2 Grouping and bypassing links WCAG Guidelines

However, this technique relies on using the name attribute on an anchor tag:

<h2><a name="content">Content</a></h2>

Along with the skip-to link:

<a href="#content">Skip to content</a>

The problem is, the "name" attribute of the anchor tag is obsolete in HTML5. HTML Obsolete Features

Is there any other way to achieve this "skip to" functionality without using the name attribute?

Footnote: The status of the HTML5 specification in still in draft and it is possible that the name attribute will actually continue to be allowed in this scenario - although it will probably still generate a "warning". It has currently been marked as "obsolete but conforming", which means you COULD still use it - however, I would like to know of other ways to perform the "skip to" to see if there is a way to do it that doesn't rely on an obsolete attribute.

解决方案

Instead of using <a> tags, you can use any element with the id attribute:

<h2 id="content">Content</h2> <a href="#content">Skip to content</a>

EDIT, found you a source (albeit it's Wikipedia ;-)):

Alternatively (and sometimes concurrently), with the name or id attributes set, the element becomes a target. A Uniform Resource Locator can link to this target via a fragment identifier. Any element can now be made into an anchor by using the id attribute,[2] so using <a name="foo"> is not necessary.

en.wikipedia/wiki/HTML_element#Anchor

更多推荐

当名称属性已过时HTML5如何跳过导航

本文发布于:2023-11-24 10:10:34,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跳过   属性   名称

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!