Change Bootstrap 4 checkbox background color

前端 未结 3 950
心在旅途
心在旅途 2020-12-28 15:01

I\'m wondering how can I change Bootstraps 4 checkbox background color on this given example.

    

        
3条回答
  •  天命终不由人
    2020-12-28 15:31

    you can use the following css to make it red when it is not checked, and black when it is checked

    .custom-control-label:before{
      background-color:red;
    }
    .custom-checkbox .custom-control-input:checked~.custom-control-label::before{
      background-color:black;
    }
    

    The color of the arrow can be changed by the following code

    .custom-checkbox .custom-control-input:checked~.custom-control-label::after{
      background-image:url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='red' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z'/%3E%3C/svg%3E");
    }
    

    this code will make the tick red, you can change the color by changing the fill='red' value to a color of your choice.

    Edit: Note, if specifying RGB color, eg. #444444 use %23 for the hash, eg. %23444444

    Or you could use any image you like instead.

    
    
      
    
    

    EDIT: added a focus color (pinkish) after a request from @cprcrack

提交回复
热议问题