如何使元素向右浮动并仍然保持 tabindex?
这是一个小提琴: http://jsfiddle.net/5s7vv/
我想做的是有 2 个按钮向左浮动,向右浮动 2 个,就像示例一样,但 button_4 应该是最右边的元素。但是,我无法仅通过简单的浮动权利来实现这一点。我应该更改它们在标记中的顺序,但这会破坏用户体验(按钮之间的选项卡顺序错误),这实际上导致了我的问题。
是否可以以正确的顺序向右浮动两个按钮,并仍然保留其选项卡索引,当然没有额外的标记。 (将它们包装在 div 中很容易,但我真的想避免这种情况)。
我知道 tabindex 属性,但据我所知它没有得到很好的支持...
HTML 代码:
CSS:
#container{
width: 200px;
}
#container a{
width: 20px;
height: 20px;
}
.button_1, .button_2{
float: left;
}
.button_3, .button_4{
float: right;
}
.button_1{background-color: blue;}
.button_2{background-color: red;}
.button_3{background-color: green;}
.button_4{background-color: yellow;}
Here is a fiddle: http://jsfiddle.net/5s7vv/
What I want to do is have 2 buttons floated left and 2 right, just like the example, but button_4 should be the rightmost element. However, I cannot achieve that by just a simple float right. I should change their order in the markup, but that breaks user experience (tabbing between buttons is in wrong order), which actually leads to my question.
Is it possible to float both buttons right, in the correct order and still keep their tab index, and of course without extra markup. (wrapping them in div is easy, but I really want to avoid that).
I know the tabindex property, but as far as I know its not well supported...
HTML Code:
CSS:
#container{
width: 200px;
}
#container a{
width: 20px;
height: 20px;
}
.button_1, .button_2{
float: left;
}
.button_3, .button_4{
float: right;
}
.button_1{background-color: blue;}
.button_2{background-color: red;}
.button_3{background-color: green;}
.button_4{background-color: yellow;}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有点麻烦,但您可以将按钮 3 和 4 包装在 div 中并使 div 右浮动。这将使按钮顺序保持不变。
It's a bit of a hack, but you could wrap buttons 3 and 4 in a div and right-float the div. That would keep the button order intact.
添加这个:
这使得它们(3和4}“交换”位置
或
position:relative
可能也会起作用更新:使用相对位置似乎在IE中更稳定..
add this:
this makes them (3 & 4} "swap" places
or
position: relative
would probably work tooUpdate: using position relative seems to be more stable in IE..