div+css实现逼真立体checkbox开关按钮效果代码

代码语言:html

所属分类:表单美化

代码描述:div+css实现逼真立体checkbox开关按钮效果代码

代码标签: div css 逼真 立体 checkbox 开关 按钮

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

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

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

  
<style>
body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  row-gap: 0.5em;
  min-height: 100vh;
  background-color: #e8e1d6;
  font-size: 3em;
}

.toggle-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  border-radius: 0.5em;
  padding: 0.125em;
  background-image: linear-gradient(to bottom, #d0c4b8, #f5ece5);
  box-shadow: 0 1px 1px rgba(255, 255, 255, 0.6);
}

.toggle-checkbox {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  z-index: 1;
  border-radius: inherit;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.toggle-container {
  display: flex;
  align-items: center;
  position: relative;
  border-radius: 0.375em;
  width: 3em;
  height: 1.5em;
  background-color: #e1dacd;
  box-shadow: inset 0 0 0.0625em 0.125em rgba(255, 255, 255, 0.2), inset 0 0.0625em 0.125em rgba(0, 0, 0, 0.4);
  transition: background-color 0.4s linear;
}
.toggle-checkbox:checked + .toggle-container {
  background-color: #f3b519;
}

.toggle-button {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  left: 0.0625em;
  border-radius: 0.3125em;
  width: 1.375em;
  height: 1.375em;
  background-color: #e4ddcf;
  box-shadow: inset 0 -0.0625em 0.0625em 0.125em rgba(0, 0, 0, 0.1), inset 0 -0.125em 0.0625em rgba(0, 0, 0, 0.2), inset 0 0.1875em 0.0625em rgba(255, 255, 255, 0.3), 0 0.125em 0.125em rgba(0, 0, 0, 0.5);
  transition: left 0.4s;
}
.toggle-checkbox:checked + .toggle-container > .toggle-button {
  left: 1.5625em;
}

.toggle-button-circles-container {
  display: grid;
  grid-template-columns: repeat(3, min-content);
  gap: 0.125em;
  position: absolute;
  margin: 0 auto;
}

.toggle-button-circle {
  border-radius: 50%;
  width: 0.125em;
  height: 0.125em;
  background-image: radial-gradient(circle at 50% 0, #f6f0e9, #bebcb0);
}
</style>

  
  
</head>

<body>
  <div class="toggle-wrapper">
  <input class="toggle-checkbox" type="checkbox">
  <div class="toggle-.........完整代码请登录后点击上方下载按钮下载查看

网友评论0