Change Bootstrap input focus blue glow

后端 未结 19 2024
抹茶落季
抹茶落季 2020-11-30 16:53

Does anyone know the how to change Bootstrap\'s input:focus? The blue glow that shows up when you click on an input field?

相关标签:
19条回答
  • 2020-11-30 17:10

    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;
    }
    
    0 讨论(0)
  • 2020-11-30 17:10

    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; }
    
    0 讨论(0)
  • 2020-11-30 17:11

    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.

    0 讨论(0)
  • 2020-11-30 17:13

    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);
      }
    }
    
    0 讨论(0)
  • 2020-11-30 17:16

    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);
    }
    
    0 讨论(0)
  • 2020-11-30 17:18

    You can modify the .form-control:focus color without altering the bootstrap style in this way:

    Quick fix

    .form-control:focus {
            border-color: #28a745;
            box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
        } 
    

    Full explanation

    1. Find the bootstrapCDN version that you are using. E.g. for me right now is 4.3.1: https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.css
    2. Search for the class you want to modify. E.g. .form-control:focus and copy the parameters that you want to modify into your css. In this case is border-color and box-shadow.
    3. Choose a color for the 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.
    4. Convert the color you have picked to RGB and add that to the box-shadow parameter without altering the fourth RGBA parameter (0.25) that bootstrap has for transparency.
    0 讨论(0)
提交回复
热议问题