css实现checkbox折纸对折开关点击效果代码

代码语言:html

所属分类:布局界面

代码描述:css实现checkbox折纸对折开关点击效果代码

代码标签: css checkbox 折纸 对折 开关 点击

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

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

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

  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
  
  <link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,100..1000&amp;display=swap'>
  
<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%);
  --trans-dur: 0.3s;
  --trans-timing: cubic-bezier(0.65,0,0.35,1);
  font-size: calc(48px + (144 - 48) * (100vw - 280px) / (3840 - 280));
}

body,
input {
  color: var(--fg);
  font: 1em/1.5 "DM Sans", sans-serif;
}

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

form {
  margin: auto;
}

.switch {
  display: flex;
}
.switch, .switch__input {
  border-radius: 0.75em;
  -webkit-tap-highlight-color: transparent;
}
.switch__input {
  box-shadow: 0 0 0.125em 0.125em hsla(var(--hue), 90%, 50%, 0);
  cursor: pointer;
  outline: transparent;
  width: 100%;
  height: 100%;
  transition: box-shadow calc(var(--trans-dur) / 2);
  -webkit-appearance: none;
  appearance: none;
  z-index: 1;
}
.switch__input, .switch__input:before, .switch__input:after {
  display: block;
  position: absolute;
}
.switch__input:before, .switch__input:after {
  backface-visibility: hidden;
  background-color: var(--bg);
  top: 0.0625em;
  width: calc(50% - 0.0625em);
  height: calc(100% - 0.125em);
  transition: background-color var(--trans-dur), color var(--trans-dur), box-shadow var(--trans-dur) var(--trans-timing), transform var(--trans-dur) var(--trans-timing);
}
.switch__input:before {
  border-radius: 0 0.75em 0.75em 0;
  box-shadow: 0.25em 0 0.25em 0 hsla(var(--hue), 10%, 10%, 0);
  content: "";
  left: 50%;
  transform: rotateY(-180deg);
  transform-origin: 0 50%;
}
[dir=rtl] .switch__input:before {
  border-radius: 0.75em 0 0 0.75em;
  box-shadow: -0.25em 0 0.25em 0 hsla(var(--hue), 10%, 10%, 0);
  right: 50%;
  left: auto;
  transform: rotateY(180deg);
  transform-origin: 100% 50%;
}
.switch__input:after {
  background-image: radial-gradient(0.25em 0.25em at center, hsla(var(--hue), 0%, 0%, 0.05) 20%, hsla(var(--hue), 0%, 0%, 0.15) 35%, hsla(var(--hue), 0%, 0%, 0) 50%), radial-gradient(0.2em 0.125em at 50% calc(50% - 0.0625em), white 37.5%, rgba(255, 255, 255, 0) 50%);
  border-radius: 0.75em 0 0 0.75em;
  box-shadow: -0.0625em 0 0.0625em 0 hsla(var(--hue), 10%, 10%, 0.5);
  content: "";
  right: 50%;
  transform-origin: 100% 50%;
  z-index: 1;
}
[dir=rtl] .switch__input:after {
  border-radius: 0 0.75em 0.75em 0;
  box-shadow: 0.0625em 0 0.0625em 0 hsla(var(--hue), 10%, 10%, 0.5);
  right: auto;
  left: 50%;
  transform-origin: 0 50%;
}
.switch__input:active:before {
  transform: rotateY(-150deg);
}
[dir=rtl] .switch__input:active:before {
  transform: rotateY(150deg);
}
.switch__input:active:after {
  box-shadow: -0.125em 0 0.25em 0 hsla(var(--hue), 10%, 10%, 0.33);
  transform: rotateY(30deg);
}
[dir=rtl] .switch__input:active:after {
  box-shadow: 0.125em 0 0.25em 0 hsla(var(--hue), 10%, 10%, 0.33);
  transform: rotateY(-30deg);
}
.switch__input:checked:before {
  box-shadow: 0 0 0.125em 0 hsla(var(--hue), 10%, 10%, 0.5);
  transform: rotateY(0);
}
.switch__input:checked:after {
  box-shadow: -0.25em 0 0.25em 0 hsla(var(--hue), 10%, 10%, 0);
  transform: rotateY(180deg);
}
[dir=rtl] .switch__input:checked:after {
  box-shadow: 0.25em 0 0.25em 0 hsla(var(--hue), 10%, 10%, 0);
  transform: rotateY(-180deg);
}
.switch__input:checked:active:before {
  box-shadow: 0.125em 0 0.25em 0 hsla(var(--hue), 10%, 10%, 0.33);
  transform: rotateY(-30deg);
}
[dir=rtl] .switch__input:checked:active:before {
  box-shadow: -0.125em 0 0.25em 0 hsla(var(--hue), 10%, 10%, 0.33);
  transform: rotateY(30deg);
}
.switch__input:checked:active:after {
  transform: rotateY(150deg);
}
[dir=rtl] .switch__input:checked:active:after {
  transform: rotateY(-150deg);
}
.switch__input:focus-visible {
  box-shadow: 0 0 0.125em 0.125em hsl(var(--hue), 90%, 50%, 0.5);
}
.switch__input-check {
  backface-visibility: hidden;
  border-radius: 0 0.75em 0.75em 0;
  color: hsl(var(--hue), 90%, 50%);
  pointer-events: none;
  top: 0;
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0