問題描述
是否可以選擇一個有焦點的元素,如 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 偽類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!