Bootstrap button - remove outline on Chrome OS X
Asked Answered
P

20

75

I am looking to achieve this: http://getbootstrap.com/javascript/#popovers-examples - scroll to the "live Demo" and hit the red popover button, in Chrome on OS X.... It's perfect beautiful

However, in my own code it outlines blue, despite a litany of CSS efforts from me to remove this!

It looks correct in Safari and Firefox but a no go in Chrome!

Prosy answered 18/1, 2014 at 6:52 Comment(1)
its not getting any blue outline thereMandie
C
134

I see .btn:focus has an outline on it:

.btn:focus {
  outline: thin dotted;
  outline: 5px auto -webkit-focus-ring-color;
  outline-offset: -2px;
}

Try changing this to:

.btn:focus {
  outline: none !important;
}

Basically, look for any instances of outline on :focused elements — that's what's causing it.

Update - For Bootstrap v4:

.btn:focus {
  box-shadow: none;
}
Cracker answered 18/1, 2014 at 6:58 Comment(5)
brilliant I placed this: .btn:hover, .btn:focus { outline: none; text-decoration: none; } .btn { outline: none; text-decoration: none; } Is any of this too heavy handed?Prosy
If you want to remove the outline during a click too, try this: .btn:focus, .btn:active:focus, .btn.active:focus { outline: none; ! important; outline-style: none; }Avrilavrit
Anyone knows why they did that?Antepast
The dotted border is used as a tool when navigating the website using a keyboardHandwriting
.btn:focus { box-shadow: none !important; } Solves the problem completely :)Payday
E
41

For any googlers like me, where..

.btn:focus {
    outline: none;
}

still didn't work in Google Chrome, the following should completely remove any button glow.

.btn:focus,.btn:active:focus,.btn.active:focus,
.btn.focus,.btn:active.focus,.btn.active.focus {
    outline: none;
}
Exhaustive answered 28/1, 2015 at 15:42 Comment(3)
I only needed .btn:focus, .btn:active, .btn:active:focus, your answer pointed me in the right direction though, so thanks!Adhesion
You may also want to add box-shadow: none;Herriott
For more context to people searching, using .btn:active:focus fixes the issue in Chrome where clicking on the button briefly flashes the blue outline. Evidently, at least in Chrome, both :focus and :active states are briefly activated when you click on the button, so you need the additional selector to address the issue.Uriia
S
38
.btn:focus, .btn:active:focus, .btn.active:focus{
    outline:none;
    box-shadow:none;
}

This should remove outline and box shadow

Showbread answered 7/4, 2015 at 6:8 Comment(1)
It was the box-shadow. Thanks!Haustellum
P
19

In bootstrap 4 the outline is no longer used, but the box-shadow. If it is your case, just do the following:

.btn:focus {
    box-shadow: none;
}
Penholder answered 2/1, 2018 at 14:37 Comment(0)
V
7

With scss:

$btn-focus-box-shadow: none!important;
Voidance answered 4/6, 2018 at 9:18 Comment(0)
Q
6

.btn.active or .btn.focus alone cannot override Bootstrap's styles. For default theme:

.btn.active.focus, .btn.active:focus,
.btn.focus, .btn:active.focus, 
.btn:active:focus, .btn:focus {
      outline: none;
}
Quadrennial answered 6/2, 2016 at 15:21 Comment(0)
S
4

The simplest solution is: Create a CSS file and type this:

.btn:focus, .btn:active:focus, .btn.active:focus {
    box-shadow: none !important;
}
Sansen answered 25/3, 2018 at 8:39 Comment(0)
T
4

You can remove the shadow without doing any extra CSS yourself.

Normally add a button like this.
<button class="btn btn-primary">Button</button>

You can simply add shadow-none to remove the outline.
<button class="btn btn-primary shadow-none">Button</button>

Travax answered 18/6, 2022 at 17:58 Comment(0)
H
2

This will remove it - short and clean:

.btn {
    outline: none !important;
}
Hinterland answered 21/1, 2016 at 16:32 Comment(0)
P
2

Here's the solution:

#sec-one{padding: 15px 0;}
p{text-align: center;}
/*
* Change the color to any color you want;
* or set to none if you don't any outline at all.
*/
*:focus:not(a){
    outline: 2px solid #f90d0e !important;
    box-shadow: none !important;
}
<!doctype html>
<html lang="en">
<head>
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
<section id="sec-one">
<div class="container">
    <div class="row">
      <div class="col">
        <form>
          <fieldset class="form-group">
            <input type="text" class="form-control" placeholder="Full Name" required>
          </fieldset>
           <fieldset class="form-group">
            <input type="email" class="form-control" placeholder="Email Address" required>
          </fieldset>
          <fieldset class="form-group">
            <input type="submit" class="btn btn-default" value="Sign Up">
          </fieldset>
          </form>
      </div>
    </div>
</div>
</section>
</body>
</html>

This works 100% hope it helps you.

Publicist answered 15/12, 2018 at 15:53 Comment(0)
M
1

Search and replace

outline: thin dotted;
outline: 5px auto -webkit-focus-ring-color;

Replace to

outline: 0;
Murry answered 11/4, 2014 at 12:54 Comment(1)
Definitely don't replace anything in the native Bootstrap files. Override them and leave the originals pristine, which is what makes CSS great. I know this answer is old but in case anyone came across this I wanted to make sure this was noted.Cheep
S
1

If the above answers still do not work, add this:

button:focus{
    outline: none!important;
    box-shadow:none;
}
Selfwill answered 11/9, 2018 at 9:35 Comment(0)
E
1

It worked for my bootstrap button after a such stress

.btn:focus,
.btn:active:focus,
.btn.active:focus,
.btn.focus,
.btn:active.focus,
.btn.active.focus {
    outline: none!important;
    box-shadow: none;
}
Effort answered 4/12, 2019 at 4:21 Comment(0)
H
1
textarea:focus, 
textarea.form-control:focus, 
input.form-control:focus, 
button.btn:focus, 
button.btn:active, 
input[type=text]:focus, 
input[type=password]:focus, 
input[type=email]:focus, 
input[type=number]:focus, 
[type=text].form-control:focus, 
[type=password].form-control:focus, 
[type=email].form-control:focus, 
[type=tel].form-control:focus, 
[contenteditable].form-control:focus {
  box-shadow: inset 0 -1px 0 #ddd;
    outline: none !important;
}
Hollander answered 15/12, 2021 at 19:0 Comment(0)
A
0

you can put this tag into your html.

<button class='btn btn-primary' onfocus='this.blur'>
     Button Text
</button>

I used on focus because onclick still displayed the glow for a microsecond and made a horrible looking flash in terms of using it. This seemed to get rid after all the css methods failed.

Adabelle answered 16/9, 2015 at 9:20 Comment(0)
O
0

That CSS goes from this file "tab-focus.less" in mixins folder (it could be difficult to find, because mixins are not shown at chrome dev-tools). So you should edit this:

// WebKit-style focus 

.tab-focus() {
      // Default
      outline: thin dotted;
      // WebKit
      outline: 5px auto -webkit-focus-ring-color;
      outline-offset: -2px;
    }
Ornithischian answered 18/12, 2015 at 11:32 Comment(0)
D
0

In the mixins of the Bootstrap sources Sass files, remove all $border references (not in the outline variant).

@mixin button-variant($color, $background, $border){ 
$active-background: darken($background, 10%);
//$active-border: darken($border, 12%);    
  color: $color;
  background-color: $background;
  //border-color: $border;
  @include box-shadow($btn-box-shadow);
  [...]
}

Or simply code you own _customButton.scss mixin.

Dendrology answered 11/5, 2017 at 9:19 Comment(0)
C
0

If someone is using bootstrap sass note the code is on the _reboot.scss file like this:

button:focus {
  outline: 1px dotted;
  outline: 5px auto -webkit-focus-ring-color;
}

So if you want to keep the _reboot file I guess feel free to override with plain css instead of trying to look for a variable to change.

Coping answered 1/10, 2018 at 17:45 Comment(0)
M
0

Bootstrap 5 and up

.btn-primary {--bs-btn-focus-shadow-rgb: none;}

Montero answered 11/7, 2022 at 15:56 Comment(0)
G
-1

If you are using bootstrap v5.1 or any other version. To remove the outline of your bootstrap navbar toggle button do this:

.navbar-toggler:focus {
    box-shadow: none !important;
}
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">

    <title>navbar</title>
  </head>
  <body>
  
  <div class="collapse" id="navbarToggleExternalContent">
  <div class="bg-dark p-4">
    <h5 class="text-white h4">Navbar toggler button</h5>
    <span class="text-muted">Check the CSS to see how to remove the outline of the toggler button.</span>
  </div>
</div>
<nav class="navbar navbar-dark bg-dark">
  <div class="container-fluid">
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
  </div>
</nav>

    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <!--
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-W8fXfP3gkOKtndU4JGtKDvXbO53Wy8SZCQHczT5FMiiqmQfUpWbYdTil/SxwZgAN" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-skAcpIdS7UcVUC05LJ9Dxay8AXcDYfBJqt1CJ85S/CFujBsIzCIv+l9liuYLaMQ/" crossorigin="anonymous"></script>
    -->
  </body>
</html>

Hope this answer will help you.

Giacinta answered 24/9, 2021 at 6:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.