Increase bootstrap custom-control custom-switch size only with css

后端 未结 2 593
我在风中等你
我在风中等你 2021-01-16 20:56

Hello I\'m trying to increase the size of a custom-control custom-switch element only with css but it\'s not working.

My custom-switch now is the default size like

相关标签:
2条回答
  • 2021-01-16 21:06

    To simply change the size, I think one can scale on the custom-control-input class.

    .custom-control-input {
      transform: scale(1.4);
    }
    
    0 讨论(0)
  • 2021-01-16 21:16

    A simple idea to change size

    .custom-control-label::before ,.custom-control-label::after{width:20px; height:20px}
    

    A detail one

    .custom-control-label { // added for alignment with the switch
      padding-top: 0.5rem;
      padding-left: 2rem;
      padding-bottom: 0.1rem;
    }
    
    .custom-switch .custom-control-label::before {
      left: -2.25rem;
      height: 2rem;
      width: 3.5rem;    // it was 1.75rem before. Sliding way is longer than before.
      pointer-events: all;
      border-radius: 1rem;
    }
    
    .custom-switch .custom-control-label::after {
      top: calc(0.25rem + 2px);
      left: calc(-2.25rem + 2px);
      width: calc(2rem - 4px);   // it was calc(1rem - 4px) before. Oval is bigger than before.
      height: calc(2rem - 4px);  // it was calc(1rem - 4px) before. Oval is bigger than before.
      background-color: #adb5bd;
      border-radius: 2rem; //   it was 0.5rem before. Oval is bigger than before.
      transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, -webkit-transform 0.15s ease-in-out;
      transition: transform 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
      transition: transform 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, -webkit-transform 0.15s ease-in-out;
    }
    @media (prefers-reduced-motion: reduce) {
      .custom-switch .custom-control-label::after {
        transition: none;
      }
    }
    
    .custom-switch .custom-control-input:checked ~ .custom-control-label::after {
      background-color: #fff;
      -webkit-transform: translateX(1.5rem); //translateX(0.75rem);
      transform: translateX(1.5rem); //translateX(0.75rem);
    }
    
    0 讨论(0)
提交回复
热议问题