Remove blue border from css custom-styled button in Chrome

前端 未结 22 947
闹比i
闹比i 2020-11-22 17:10

I\'m working on a web page, and I want custom-styled

相关标签:
22条回答
  • 2020-11-22 17:24

    Don't forget the !important declaration, for a better result

    button:focus {outline:0 !important;}
    

    A rule that has the !important property will always be applied no matter where that rule appears in the CSS document.

    0 讨论(0)
  • 2020-11-22 17:24

    Most of the solutions will not work if you're using Bootstrap 4.1 and possibly other versions. After much head banging, I discovered you need to apply the shadow-none class:

    <button class="btn shadow-none">Bootstrap (4.1) button without shadow</button>
    
    0 讨论(0)
  • 2020-11-22 17:28

    Ok, even with the risk of never getting anyone to see this, because there are already so many answers I wanted to offer more js solutions as of the year 2020 there are plenty:

    outline.js or alternatively outliner.js both libraries solving exactly the issues we all have here: remove outlines for mice but keep keyboard functionality or accessability.

    So instead of deciding which is more important style or accessability, choose both!

    0 讨论(0)
  • 2020-11-22 17:31

    Doing this is not recommended as it regresses the accessibility of your site; for more info, see this post.

    That said, if you insist, this CSS should work:

    button:focus {outline:0;}
    

    Check it out or JSFiddle: http://jsfiddle.net/u4pXu/

    Or in this snippet:

    button.launch {
    background-color: #F9A300;
    border: none;
    height: 40px;
    padding: 5px 15px;
    color: #ffffff;
    font-size: 16px;
    font-weight: 300;
    margin-top: 10px;
    margin-right: 10px;
    }
    
    button.launch:hover {
    cursor: pointer;
    background-color: #FABD44;
    }
    
    button.launch {
    background-color: #F9A300;
    border: none;
    height: 40px;
    padding: 5px 15px;
    color: #ffffff;
    font-size: 16px;
    font-weight: 300;
    margin-top: 10px;
    margin-right: 10px;
    }
    
    button.launch:hover {
    cursor: pointer;
    background-color: #FABD44;
    }
    
    button.change {
    background-color: #F88F00;
    border: none;
    height: 40px;
    padding: 5px 15px;
    color: #ffffff;
    font-size: 16px;
    font-weight: 300;
    margin-top: 10px;
    margin-right: 10px;
    }
    
    button.change:hover {
    cursor: pointer;
    background-color: #F89900;
    }
    
    button:active {
    outline: none;
    border: none;
    }
    
    button:focus {outline:0;}
    <button class="launch">Launch with these ads</button> 
    <button class="change">Change</button>

    0 讨论(0)
  • 2020-11-22 17:31

    Another way to solve the accessibility problem that hasn't been mentioned here yet is through a little bit of Javascript. Credits go this insightful blogpost from hackernoon: https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2

    The approach here is really simple yet effective: Adding a class when people start using the tab-key to navigate the page (and optionally remove it when the switch to mouse again. Then you can use this class to either display a focus outline or not.

    function handleFirstTab(e) {
        if (e.keyCode === 9) { // the "I am a keyboard user" key
            document.body.classList.add('user-is-tabbing');
            window.removeEventListener('keydown', handleFirstTab);
        }
    }
    
    window.addEventListener('keydown', handleFirstTab);
    
    0 讨论(0)
  • 2020-11-22 17:31

    I faced the same issue so I used simple CSS-

    .custom-button {
        outline: none
    }
    
    0 讨论(0)
提交回复
热议问题