svg+css模拟实体按键开关效果代码

代码语言:html

所属分类:布局界面

代码描述:svg+css模拟实体按键开关效果代码

代码标签: svg css 模拟 实体 按键 开关

下面为部分代码预览,完整代码请点击下载或在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;
  gap: 1em;
  min-height: 100vh;
  background-image: linear-gradient(45deg, #47b6d1, #90e0ec);
  font-size: 2em;
}

.toggle-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  column-gap: 0.25em;
}

.toggle-icon {
  width: 0.5em;
  height: 0.5em;
  fill: #4c9bab;
  filter: drop-shadow(0 1px 1px rgba(255, 255, 255, 0.4));
  transition: fill 0.4s;
}
.toggle-checkbox:not(:checked) + .toggle-icon.off, .toggle-checkbox:checked ~ .toggle-icon.on {
  fill: #e0f9fc;
}

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

.toggle-container {
  position: relative;
  border-radius: 3.125em;
  width: 4.05em;
  height: 1.5em;
  background-image: repeating-conic-gradient(#0b66a0 0% 25%, #1093a8 0% 50%);
  background-size: 0.125em 0.125em;
  box-shadow: inset 0 0.125em 0.25em rgba(0, 9, 38, 0.6), inset -1.5em 0 0.0625em rgba(0, 9, 38, 0.5), inset 0.5em 0 0.5em rgba(0, 9, 38, 0.5), 0 1px 1px rgba(255, 255, 255, 0.4);
}

.toggle-button {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  top: 0.0625em;
  left: 0.0625em;
  border-radius: inherit;
  width: 2.55em;
  height: calc(100% - .125em);
  background-image: linear-gradient(to right, #86e2fa, #125e79);
  box-shadow: 0 0.125em 0.25em rgba(0, 0, 0, 0.6);
  transition: left 0.4s;
}
.toggle-checkbox:checked ~ .toggle-container > .toggle-button {
  left: 1.4375em;
}
.toggle-button::before {
  content: "";
  position: absolute;
  top: inherit;
  border-radius: inherit;
  width: calc(100% - .375em);
  height: inherit;
  background-image: linear-gradient(to right, #0f73a8, #57cfe2, #b3f0ff);
}
.toggle-button::after {
  content: "&qu.........完整代码请登录后点击上方下载按钮下载查看

网友评论0