CSS中的tabindex [英] tabindex in CSS

查看:684
本文介绍了CSS中的tabindex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用CSS控制tabindex?如果是,哪些浏览器支持它和哪些元素?

Is it possible to control tabindex with CSS and if yes, which browsers support it and on which elements?

EDIT

EDIT

我应该说,我的目标是在div上捕获keydown事件。我看到此网页 http://www.quirksmode.org/js/events/keys.html#测试键盘事件,它表明keydown在除文档和正文或某种形式元素或链接之外的任何东西的唯一方式是在其上声明tabindex。但是我在W3C网站上阅读:

I should say, my goal is to catch keydown events on a div. I saw this page http://www.quirksmode.org/js/events/keys.html# that tests keyboard events and it shows that the only way keydown fires on anything other than document and body or some kind of form element or link is to have tabindex declared on it. But I read on W3C site:


以下元素支持
tabindex属性:A,AREA,BUTTON,
INPUT,OBJECT,SELECT和TEXTAREA。

The following elements support the tabindex attribute: A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA.

所以我有点困惑,为了符合标准,使我的用例工作?

So I am a little confused, what to do in order to be standarts compliant and make my use case work?

EDIT2

div有很多内容与人工滚动条。

My whole use case is a div with a lot of content with an artificial scroll bar. I am able to scroll it with mouse events but no luck with the keyboard so far.

推荐答案

看看 nav-index 属性由W3C在 CSS3-UI

此属性的行为与 tabindex 完全相同,适用于任何元素。

This property has exactly the same behavior as a tabindex and is applicable to any element.


'nav-index'属性是一种输入法中立的方式,用于指定顺序导航顺序(也称为制表顺序 )。
此属性替换了HTML4 / XHTML1属性'tabindex'

The ‘nav-index’ property is an input-method-neutral way of specifying the sequential navigation order (also known as "tabbing order"). This property is a replacement for the HTML4/XHTML1 attribute ‘tabindex’

可能是最符合标准的解决方案用例, nav-index 仅由Opera解释(截至2012年6月),并且也被W3C标记为风险特征,因此可能会被删除

Being probably the best standards-compliant solution for the use case, nav-index is interpreted only by Opera so far (as of June 2012) and is also marked as "Feature at risk" by W3C, therefore may be dropped any time.

替代的跨浏览器解决方案是:

Alternative cross-browser solutions are:


  • 不符合标准:在 DIV 上设置 tabindex 属性。

符合标准:通过锚元素替换 DIV A ) c> $ c>并添加 tabindex 属性。

standards-compliant: replace DIV by an anchor element (A) without a href attribute set, style it with display: block and add the tabindex attribute.

对于BoltClock的观点,我同意Tabing的顺序是非常合乎逻辑的(文本选择顺序和Tabing顺序与文档中元素排列的顺序密切相关)。另一方面,CSS今天有更广泛的目的。它不仅可以操纵文档的内容( content 属性),还可以操作何时和如果事件被触发:ie using pointer-事件显示 z-index 如果这些是非常基本的CSS属性,为什么你也不能影响KeyBoardEvents?

With respect to BoltClock´s point, I agree that the tabbing order is very logical (both the text selection order and tabbing order are closely related to the sequence in which elements are aranged in the document). On the other hand, CSS has a wider purpose today. It can manipulate not just the content of a document (content property) but also the behavior when and if events are to be fired: i.e. using pointer-events, display or z-index the pointer event's order will change. If these are very basic CSS properties, why you should not be able to influence KeyBoardEvents, too?

这篇关于CSS中的tabindex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆