Remove Safari/Chrome textinput/textarea glow

后端 未结 13 843

I am wondering if its possible to remove the default blue and yellow glow when I click on a text input / text area using CSS?

相关标签:
13条回答
  • 2020-11-28 18:12

    some times it's happens buttons also then use below to remove the outerline

    input:hover
    input:active, 
    input:focus, 
    textarea:active,
    textarea:hover,
    textarea:focus, 
    button:focus,
    button:active,
    button:hover
    {
        outline:0px !important;
    }
    
    0 讨论(0)
  • 2020-11-28 18:13

    I found it helpful to remove the outline on a "sliding door" type of input button, because the outline doesn't cover the right "cap" of the sliding door image making the focus state look a little wonky.

    input.slidingdoorbutton:focus { outline: none;}
    
    0 讨论(0)
  • 2020-11-28 18:19

    Edit (11 years later): Don't do this unless you're going to provide a fallback to indicate which element is active. Otherwise, this harms accessibility as it essentially removes the indication showing which element in a document has focus. Imagine being a keyboard user and not really knowing what element you can interact with. Let accessibility trump aesthetics here.

    textarea, select, input, button { outline: none; }
    

    Although, it's been argued that keeping the glow/outline is actually beneficial for accessibility as it can help users see which Element is currently focused.

    You can also use the pseudo-element ':focus' to only target the inputs when the user has them selected.

    Demo: https://jsfiddle.net/JohnnyWalkerDesign/xm3zu0cf/

    0 讨论(0)
  • 2020-11-28 18:25

    If you want to remove the glow from buttons in Bootstrap (which is not necessarily bad UX in my opinion), you'll need the following code:

    .btn:focus, .btn:active:focus, .btn.active:focus{
      outline-color: transparent;
      outline-style: none;
    }
    
    0 讨论(0)
  • 2020-11-28 18:27

    This is the solution for people that do care about accessibility.

    Please, don't use outline:none; for disabling the focus outline. You are killing accessibility of the web if you do this. There is a accessible way of doing this.

    Check out this article that I've written to explain how to remove the border in an accessible way.

    The idea in short is to only show the outline border when we detect a keyboard user. Once a user starts using his mouse we disable the outline. As a result you get the best of the two.

    0 讨论(0)
  • 2020-11-28 18:28

    Carl W:

    This effect can occur on non-input elements, too. I've found the following works as a more general solution

    :focus {
      outline-color: transparent;
      outline-style: none;
    }
    

    I’ll explain this:

    • :focus means it styles the elements that are in focus. So we are styling the elements in focus.
    • outline-color: transparent; means that the blue glow is transparent.
    • outline-style: none; does the same thing.
    0 讨论(0)
提交回复
热议问题