div+css实现挂锁checkbox开关效果代码

代码语言:html

所属分类:布局界面

代码描述:div+css实现挂锁checkbox开关效果代码

代码标签: div css 挂锁 checkbox 开关

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  
  
<style>
* {
  border: 0;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --hue: 223;
  --bg: hsl(var(--hue),10%,90%);
  --fg: hsl(var(--hue),10%,10%);
  --primary: hsl(var(--hue),90%,50%);
  --trans-dur: 0.3s;
  --trans-timing: cubic-bezier(0.65,0,0.35,1);
  font-size: calc(56px + (120 - 56) * (100vw - 280px) / (3840 - 280));
}

body,
input {
  font: 1em/1.5 sans-serif;
}

body {
  background-color: var(--bg);
  color: var(--fg);
  display: flex;
  height: 100vh;
  transition: background-color var(--trans-dur), color var(--trans-dur);
}

.switch {
  display: flex;
  align-items: center;
  margin: auto;
}
.switch, .switch__input {
  -webkit-tap-highlight-color: transparent;
}
.switch__handle, .switch__input, .switch__wrapper {
  display: block;
}
.switch__handle {
  filter: drop-shadow(0 0.0625em rgba(0, 0, 0, 0.15));
  pointer-events: none;
  top: 0.1875em;
  left: 0.1875em;
  width: 1.125em;
  height: 1.125em;
  transform-style: preserve-3d;
  perspective: 19.5em;
}
[dir=rtl] .switch__handle {
  right: 0.1875em;
  left: auto;
}
.switch__handle, .switch__handle-top, .switch__handle-bottom, .switch__handle-side {
  position: absolute;
}
.switch__handle-top, .switch__handle-bottom {
  border-radius: 50%;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.switch__handle-top {
  box-shadow: 0 0 0 0.25em hsl(var(--hue), 10%, 90%) inset;
  clip-path: polygon(0 0, 100% 0, 100% calc(50% + 1px), 0 calc(50% + 1px));
}
.switch__handle-bottom, .switch__handle-side {
  background-color: white;
  transition: transform var(--trans-dur) var(--trans-timing);
}
.switch__handle-bottom {
  clip-path: polygon(0 50%, 100% 50%, 100% 100%, 0 100%);
  transform: rotateY(0) translateZ(-0.125em);
  transform-origin: calc(100% - 0.125em) 0;
}
[dir=rtl] .switch__handle-bottom {
  transform-origin: 0.125em 0;
}
.switch__handle-bottom ~ .switch__handle-bottom {
  transform: rotateY(0) translateZ(0.125em);
}
.switch__handle-side {
  display: block;
  top: 50%;
  left: 0.875em;
  width: 0.25em;
  height: 50%;
  transform: rotateY(-90deg) translateZ(0.4375em);
}
[dir=rtl] .switch__handle-side {
  right: 0.875em;
  left: auto;
  transform: rotateY(90deg) translateZ(0.4375em);
}
.switch__input {
  background-color: white;
  background-image: linear-gradient(-45deg, rgba(0, 0, 0, 0) 49%, rgba(0, 0, 0, 0.2) 50%);
  border-radius: 0.75em;
  cursor: pointer;
  position: relative;
  width: 2.375em;
  height: 1.5em;
  -webkit-appearance: none;
  appearance: none;
}
.switch__input, .switch__input:before {
  transition: background-color var(--trans-dur);
}
.switch__input:before {
  background-color: hsl(var(--hue), 10%, 80%);
  border-radius: 0.625em;
  box-shadow: 0 0.0625em 0 rgba(0, 0, 0, 0.15) inset;
  content: "";
  display: block;
  position: absolute;
  top: 0.125em;
  left: 0.125em;
  width: .........完整代码请登录后点击上方下载按钮下载查看

网友评论0