1

I am working vue js project for my own skill development.

When I change bootstrap-vue toggler background color but Unfortunately background-color isn't changed? I am new in Vue js. please solve this problem if you can?

Vue Structure:-

<div class="toggler-btn">
 <b-form-checkbox v-model="checked" name="check-button" switch>
 </b-form-checkbox>
</div>

Style:-

<style scoped>
.custom-control-input:checked ~ .custom-control-label::before {
    color: #fff;
    border-color: red !important;
    background-color: red !important;
  }
</style>
TylerH
  • 20,799
  • 66
  • 75
  • 101
Nazmul
  • 33
  • 5

2 Answers2

0

This may be due to the scoped styling. Try this:

 <style scoped>

      ::v-deep(.toggler-btn) {
          .custom-control-input:checked ~ .custom-control-label::before {
              color: #fff;
              border-color: red !important;
              background-color: red !important;
          }
      }

  </style>
dantheman
  • 3,189
  • 2
  • 10
  • 18
0

Your problem is because of style scoping. You can create a global.css and put all your global styles in there. I prepared a working code snippet based on your code to see that it's working.

new Vue({
  el: '#app'
})
.custom-control-input:checked~.custom-control-label::before {
  color: #fff;
  border-color: red !important;
  background-color: red !important;
}
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap@4.5.3/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap-vue@2.21.2/dist/bootstrap-vue.css" />

<script src="https://unpkg.com/vue@2.6.12/dist/vue.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@2.21.2/dist/bootstrap-vue.min.js"></script>

<div id="app">
  <b-form-checkbox name="check-button" switch size="lg" />
</div>
Iman Shafiei
  • 1,497
  • 15
  • 21