点击查看html编辑器说明文档

CSS音量开关edit icon

|
|
Fork(复制)
|
|
作者:
穿越者X57

👉 新版编辑器已上线,点击进行体验吧!

BUG反馈
嵌入
设置
下载
HTML
格式化
支持Emmet,输入 p 后按 Tab键试试吧!
<head> ...
展开
</head>
<body>
            
            <input type="checkbox" role="switch" class="toggle" />
<input type="checkbox" role="switch" class="toggle" checked />
<input type="checkbox" role="switch" class="toggle" disabled />
<input type="checkbox" role="switch" class="toggle" disabled checked />
        
</body>
CSS
格式化
            
            body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin: 0;
  min-height: 100vh;
  font-size: 7vmin;
  gap: 0.25em;
}

.toggle {
  appearance: none;
  position: relative;
  font-size: 1em;
  width: 3em;
  height: 1em;
  border: max(1px, 0.05em) solid;
  border-radius: 20% / 100%; 2em;
  
  &::before {
    content: "";
    width: 0.7em;
    height: 0.7em;
    position: absolute;
    background: 
      linear-gradient(currentcolor 0 0) 10% 50% / 35% 45%,
      conic-gradient(at -75% 50%, #0000 62deg, currentcolor 0 118deg, #0000 0) 100% 50% / 55% 100%
      ;
    background-repeat: no-repeat;
    outline: 1px solid #0000;
    aborder-radius: 50% / 50% 100% 100% 50%;
    top: 50%;
    left: 0.5em;
    transform: translate(-50%, -50%);
    transition: left 0.5s;
  }
  
  &::after {
    content: "";
    width: 0.7em;
    height: 0.7em;
    position: absolute;
    background: 
      radial-gradient(50% 70% at -10% 50%, #0000 80%, #000 0 99%, #0000) 50% 50% / 50% 50%,
      radial-gradient(50% 70% at -10% 50%, #0000 80%, #000 0 99%, #0000) 75% 50% / 50% 60%,
      radial-gradient(50% 70% at -10% 50%, #0000 80%, #000 0 99%, #0000) 100% 50% / 50% 70%
      ;
    background-repeat: no-repeat;
    outline: 1px solid #0000;
    border-radius: 50% / 50% 100% 100% 50%;
    top: 50%;
    left: 0.5em;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: left 0.5s, opacity 0.5s;
  }
  
  &:checked {
    &::before {
      left: calc(100% - 0.85em);
    }
    
    &::after {
      left: calc(100% - 0.3em);
      opacity: 1;
    }
  }
  
  &[disabled] {
    opacity: 0.25;
  }
}

@media print {
  .toggle {
    &, &::before, &::after {
      -webkit-print-color-adjust: exact;
      print-color-adjust: exact;
    }
  }
}

@media (prefers-reduced-motion) {
  .toggle {
    &, &::before, &::after {
      transition: none !important;
      animation: none !important;
    }
  }
}
        
JS
格式化
            
            
        
预览
控制台