using :focus pseudo class on li or other element else than a,input,button, etc(在 li 或除 a、input、button 等之外的其他元素上使用 :focus 伪类)
问题描述
是否可以选择一个有焦点的元素,如 a:focus 或 input:focus,但在另一个元素上,如 div、li、span 或其他?
Is it possible to select an element that is focused, like a:focus or input:focus, but on the other element, such as div, li, span or else?
如果不可能,如何用标签代替?我正在尝试修改 li 元素在聚焦时的高度,尝试使用 a,但高度不会改变.
If it's not possible, how can it be substituted with a tag? I am trying to modify height of a li element when it's focused, tried with a, but the height won't change.
请求的信息:
你能不能解释一下你是如何把注意力放在李身上的?"
"Can you also explain how do you put focus on LI?"
通过 CSS 选择器 li:focus
.请参阅 https://jsfiddle.net/s4nji/Rjqy5/.
Via css selector li:focus
. See https://jsfiddle.net/s4nji/Rjqy5/.
推荐答案
这很简单:只需在通常不接收焦点的元素上添加一个 tabindex
属性即可.
That's simple: just add a tabindex
attribute to the elements which normally don't receive focus.
这篇关于在 li 或除 a、input、button 等之外的其他元素上使用 :focus 伪类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 li 或除 a、input、button 等之外的其他元素上使


基础教程推荐
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01