How to remove focus around buttons on click

后端 未结 30 916
遇见更好的自我
遇见更好的自我 2020-12-02 04:24

My buttons all have a highlight around them after I click them. This is in Chrome.

\"Unselected\"

相关标签:
30条回答
  • 2020-12-02 05:11

    I found this Q and A on another page, and overriding the button focus style worked for me. This problem may be specific to MacOS with Chrome.

    .btn:focus {
      outline: none;
      box-shadow: none;
    }
    

    Note though that this has implications for accessibility and isn't advised until you have a good consistent focus state for your buttons and inputs. As per the comments below, there are users out there who cannot use mice.

    0 讨论(0)
  • 2020-12-02 05:11

    I found no solid answers that didn't either break accessibility or subvert functionality.

    Perhaps combining a few will work better overall.

    <h1
      onmousedown="this.style.outline='none';"
      onclick="this.blur(); runFn(this);"
      onmouseup="this.style.outline=null;"
    >Hello</h1>
    

    function runFn(thisElem) { console.log('Hello: ', thisElem); }

    0 讨论(0)
  • 2020-12-02 05:11

    I was having the same problem using <a> acting as button and I discovered I was missing a workaround by adding attr type="button" makes it behave normally for me at least.

    <a type="button" class="btn btn-primary">Release Me!</a>

    0 讨论(0)
  • 2020-12-02 05:12

    Try this solution for remove border around the button. Add this code in css.

    Try

    button:focus{
    outline:0px;
    }
    

    If not works then use below.

    button:focus{
     outline:none !important;
     }
    
    0 讨论(0)
  • 2020-12-02 05:13

    This worked for me. I created a custom class which overrides the necessary CSS.

    .custom-button:focus {
        outline: none !important;
        border: none !important;
        -webkit-box-shadow: none !important;
        box-shadow: none !important;
    }
    

    The -webkit-box-shadow will work for Chrome and safari browsers.

    0 讨论(0)
  • 2020-12-02 05:13
      .btn:focus,.btn:active, a{
            outline: none !important;
            box-shadow: none;
         }
    

    this outline:none will work for both button and a tag

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