トグルスイッチ

by takumi091111

HTML

<div class="toggle-button">
  <input type="checkbox" class="toggle-button__input">
  <div class="toggle-button__button"></div>
</div>

SCSS

.toggle-button {
  position: relative;
  width: 40px;
  height: 21px;
  background-color: #FFD0CD;
  border-radius: 24px;
  box-sizing: content-box;
  margin: 5px 0;
  &__input {
    opacity: 0;
    appearance: none;
    position: absolute;
    width: 100%;
    height: 100%;
  }
  &__button {
    background-color: #FFF;
    position: relative;
    top: 3px;
    left: 3px;
    width: 15px;
    height: 15px;
    border-radius: 20px;
    pointer-events: none;
    transition: background-color 0.2s, transform 0.2s;
  }
  &__input:checked ~ &__button {
    transform: translateX(19px);
  }
}