css做一个好看的开关
以下是一个使用CSS实现的漂亮开关的示例:
HTML代码:
<div class="switch">
  <input type="checkbox" id="toggle" class="toggle-input">
  <label for="toggle" class="toggle-label"></label>
</div>
CSS代码:
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}
.toggle-input {
  display: none;
}
.toggle-label {
  display: block;
  position: absolute;
  cursor: pointer;
  background-color: #ccc;
  border-radius: 34px;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  transition: background-color 0.3s;
}
.toggle-label:before {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background-color: #fff;
  top: 4px;
  left: 4px;
  transition: transform 0.3s;
}
.toggle-input:checked + .toggle-label {
  background-color: #66bb6a;
}
.toggle-input:checked + .toggle-label:before {
  transform: translateX(26px);
}
这是一个基本的开关样式。你可以根据自己的需求进行样式修改和调整
原文地址: https://www.cveoy.top/t/topic/hQVg 著作权归作者所有。请勿转载和采集!