switch.css 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. .form-switch {
  2. display: inline-block;
  3. cursor: pointer;
  4. -webkit-tap-highlight-color: transparent;
  5. }
  6. .form-switch i {
  7. position: relative;
  8. display: inline-block;
  9. margin-right: 0.5rem;
  10. width: 46px;
  11. height: 26px;
  12. @apply bg-shade-6;
  13. border-radius: 23px;
  14. vertical-align: text-bottom;
  15. transition: all 0.3s linear;
  16. }
  17. .form-switch i::before {
  18. content: '';
  19. position: absolute;
  20. left: 0;
  21. width: 42px;
  22. height: 22px;
  23. background-color: #fff;
  24. border-radius: 11px;
  25. transform: translate3d(2px, 2px, 0) scale3d(1, 1, 1);
  26. transition: all 0.25s linear;
  27. }
  28. .form-switch i::after {
  29. content: '';
  30. position: absolute;
  31. left: 0;
  32. width: 22px;
  33. height: 22px;
  34. background-color: #fff;
  35. border-radius: 11px;
  36. box-shadow: 0 2px 2px rgba(0, 0, 0, 0.24);
  37. transform: translate3d(2px, 2px, 0);
  38. transition: all 0.2s ease-in-out;
  39. }
  40. .form-switch:active i::after {
  41. width: 28px;
  42. transform: translate3d(2px, 2px, 0);
  43. }
  44. .form-switch:active input:checked + i::after {
  45. transform: translate3d(16px, 2px, 0);
  46. }
  47. .form-switch input {
  48. display: none;
  49. }
  50. .form-switch input:checked + i {
  51. @apply bg-main-accent;
  52. }
  53. .form-switch input:checked + i::before {
  54. transform: translate3d(18px, 2px, 0) scale3d(0, 0, 0);
  55. }
  56. .form-switch input:checked + i::after {
  57. transform: translate3d(22px, 2px, 0);
  58. }