using :focus pseudo class on li or other element else than a,input,button, etc

前端 未结 2 1857
时光取名叫无心
时光取名叫无心 2020-12-11 16:27

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?

If it\'s not possible, ho

相关标签:
2条回答
  • 2020-12-11 16:58

    That's simple: just add a tabindex attribute to the elements which normally don't receive focus.

    0 讨论(0)
  • 2020-12-11 17:06

    You can't focus list items. Not even using a script. I've tried doing $("li:first").focus() but it doesn't do anything. CSS doesn't get set as if it was focussed. This simply means that you either can't focus list items or that :focus pseudo classes don't work on list items.

    Put anchors inside list items

    <ul>
        <li><a href="#">...</a></li>
        <li><a href="#">...</a></li>
        <li><a href="#">...</a></li>
        ...
    </ul>
    

    This will seemingly focus your list item but it will actually focus anchor tags.

    0 讨论(0)
提交回复
热议问题