How to prevent hidden element to be shown when focused in Chrome?

前端 未结 1 2022
悲哀的现实
悲哀的现实 2021-01-02 20:45

I have a strange problem today, in Chrome, when I focus on an element that is absolutely positioned out of its overflow hidden container, it gets visible in Chrome browser (

相关标签:
1条回答
  • 2021-01-02 21:17

    Use tabindex="-1" on your "inner-button". That will prevent focus. http://jsfiddle.net/GHgtc/2/

    <input placeholder="focus on me then press tab" type="text">
    <div id="container">
        <a id="inner-button" tabindex="-1" href="#">You can see me !</a>
    </div>
    

    UPDATE:

    I realized there is another possible solution to your issue while working on some focus issue of my own. You can use z-index:-1 if the focus you need is to be triggered later via javascript event.

    #inner-button{
        display: block;
        background: red;
        width: 20px;
        height: 20px;
        position: absolute;
        top: 5px;
        right: -20px;
        z-index:-1;
    }
    

    http://jsfiddle.net/GHgtc/3/

    That will keep it focusable but hidden. And you can make it visible back with z-index:0 dynamically.

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