Change hover color on a button with Bootstrap customization

前端 未结 4 1674
独厮守ぢ
独厮守ぢ 2020-12-24 01:30

I am trying to style my buttons in a way that the hover makes the button a lighter shade instead of a darker shade. I tried bootstrap customization page(http://getbootstrap.

相关标签:
4条回答
  • 2020-12-24 01:48

    The color for your buttons comes from the btn-x classes (e.g., btn-primary, btn-success), so if you want to manually change the colors by writing your own custom css rules, you'll need to change:

    /*This is modifying the btn-primary colors but you could create your own .btn-something class as well*/
    .btn-primary {
        color: #fff;
        background-color: #0495c9;
        border-color: #357ebd; /*set the color you want here*/
    }
    .btn-primary:hover, .btn-primary:focus, .btn-primary:active, .btn-primary.active, .open>.dropdown-toggle.btn-primary {
        color: #fff;
        background-color: #00b3db;
        border-color: #285e8e; /*set the color you want here*/
    }
    
    0 讨论(0)
  • 2020-12-24 02:06

    or can do this...
    set all btn ( class name like : .btn- + $theme-colors: map-merge ) styles at one time :

    @each $color, $value in $theme-colors {
      .btn-#{$color} {
        @include button-variant($value, $value,
        // modify
        $hover-background: lighten($value, 7.5%),
        $hover-border: lighten($value, 10%),
        $active-background: lighten($value, 10%),
        $active-border: lighten($value, 12.5%)
        // /modify
        );
      }
    }
    
    // code from "node_modules/bootstrap/scss/_buttons.scss"
    

    should add into your customization scss file.

    0 讨论(0)
  • 2020-12-24 02:08

    This is the correct way to change btn color.

     .btn-primary:not(:disabled):not(.disabled).active, 
        .btn-primary:not(:disabled):not(.disabled):active, 
        .show>.btn-primary.dropdown-toggle{
            color: #fff;
            background-color: #F7B432;
            border-color: #F7B432;
        }
    
    0 讨论(0)
  • 2020-12-24 02:10

    I had to add !important to get it to work. I also made my own class button-primary-override.

    .button-primary-override:hover, 
    .button-primary-override:active,
    .button-primary-override:focus,
    .button-primary-override:visited{
        background-color: #42A5F5 !important;
        border-color: #42A5F5 !important;
        background-image: none !important;
        border: 0 !important;
    }
    
    0 讨论(0)
提交回复
热议问题