Does anyone know the how to change Bootstrap\'s input:focus
? The blue glow that shows up when you click on an input
field?
Here are the changes if you want Chrome to show the platform default "yellow" outline.
textarea:focus, input[type="text"]:focus, input[type="password"]:focus, input[type="datetime"]:focus, input[type="datetime-local"]:focus, input[type="date"]:focus, input[type="month"]:focus, input[type="time"]:focus, input[type="week"]:focus, input[type="number"]:focus, input[type="email"]:focus, input[type="url"]:focus, input[type="search"]:focus, input[type="tel"]:focus, input[type="color"]:focus, .uneditable- input:focus {
border-color: none;
box-shadow: none;
-webkit-box-shadow: none;
outline: -webkit-focus-ring-color auto 5px;
}
I landed to this thread looking for the way to disable glow altogether. Many answers were overcomplicated for my purpose. For easy solution, I just needed one line of CSS as follows.
input, textarea, button {outline: none; }
In Bootstrap 4, if you compile SASS by yourself, you can change the following variables to control the styling of the focus shadow:
$input-btn-focus-width: .2rem !default;
$input-btn-focus-color: rgba($component-active-bg, .25) !default;
$input-btn-focus-box-shadow: 0 0 0 $input-btn-focus-width $input-btn-focus-color !default;
Note: as of Bootstrap 4.1, the $input-btn-focus-color
and $input-btn-focus-box-shadow
variables are used only for input elements, but not for buttons. The focus shadow for buttons is hardcoded as box-shadow: 0 0 0 $btn-focus-width rgba($border, .5);
, so you can only control the shadow width via the $input-btn-focus-width
variable.
If you are using Bootstrap 3.x, you can now change the color with the new @input-border-focus
variable.
See the commit for more info and warnings.
In _variables.scss update @input-border-focus
.
To modify the size/other parts of this glow modify the mixins/_forms.scss
@mixin form-control-focus($color: $input-border-focus) {
$color-rgba: rgba(red($color), green($color), blue($color), .6);
&:focus {
border-color: $color;
outline: 0;
@include box-shadow(inset 0 1px 1px rgba(0,0,0,.075), 0 0 4px $color-rgba);
}
}
This will work 100% use this:
.form-control, .form-control:focus{
box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
border: rgba(255, 255, 255, 0);
}
You can modify the .form-control:focus
color without altering the bootstrap style in this way:
.form-control:focus {
border-color: #28a745;
box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
}
.form-control:focus
and copy the parameters that you want to modify into your css. In this case is border-color
and box-shadow
.border-color
. In this case I choose to pick up the same green the bootstrap uses for their .btn-success
class, by searching for that particular class in the bootstrap.css page mentioned in the step 1.box-shadow
parameter without altering the fourth RGBA parameter (0.25) that bootstrap has for transparency.