纯css实现checkbox多种动画效果

代码语言:html

所属分类:表单美化

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

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<link href="https://fonts.googleapis.com/css?family=Margarine|Rubik:400,500" rel="stylesheet">


<style>
body {
  background: #2e394d;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

* {
  box-sizing: border-box;
}
*:before, *:after {
  content: '';
  position: absolute;
}

input {
  height: 40px;
  left: 0;
  opacity: 0;
  position: absolute;
  top: 0;
  width: 40px;
}

.toggle-wrapper {
  flex: 1 1 calc(100% / 3);
  min-height: 50vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
@media (max-width: 960px) {
  .toggle-wrapper {
    flex: 1 1 calc(100% / 2);
  }
}
@media (max-width: 700px) {
  .toggle-wrapper {
    flex: 1 1 100%;
  }
}
.toggle-wrapper:nth-child(1) {
  background: #dec387;
}
.toggle-wrapper:nth-child(2) {
  background: #de8797;
}
.toggle-wrapper:nth-child(3) {
  background: #87aade;
}
.toggle-wrapper:nth-child(4) {
  background: #c5de87;
}
.toggle-wrapper:nth-child(5) {
  background: #87ded2;
}
.toggle-wrapper:nth-child(6) {
  background: #c487de;
}
.toggle-wrapper:nth-child(7) {
  background: #de8787;
}
.toggle-wrapper:nth-child(7) .toggle {
  transform: translate(-40px, 40px);
}
.toggle-wrapper:nth-child(8) {
  background: #decf87;
}
.toggle-wrapper:nth-child(8) .toggle {
  transform: translate(-40px, 40px);
}

.name {
  width: 80%;
  position: absolute;
  font: 500 14px 'Rubik', sans-serif;
  letter-spacing: .5px;
  text-transform: uppercase;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
  bottom: 15px;
  right: 15px;
  text-align: right;
}

.toggle {
  position: relative;
  display: inline-block;
}

label.toggle-item {
  width: 7em;
  background: #2e394d;
  height: 3em;
  display: inline-block;
  border-radius: 50px;
  margin: 40px;
  position: relative;
  transition: all .3s ease;
  transform-origin: 20% center;
  cursor: pointer;
}
label.toggle-item:before {
  display: block;
  transition: all .2s ease;
  width: 2.3em;
  height: 2.3em;
  top: .25em;
  left: .25em;
  border-radius: 2em;
  border: 2px solid #88cf8f;
  transition: .3s ease;
}

.normal label {
  background: #af4c4c;
  border: 0.5px solid rgba(117, 117, 117, 0.31);
  box-shadow: inset 0px 0px 4px 0px rgba(0, 0, 0, 0.2), 0 -3px 4px rgba(0, 0, 0, 0.15);
}
.normal label:before {
  border: none;
  width: 2.5em;
  height: 2.5em;
  box-shadow: inset 0.5px -1px 1px rgba(0, 0, 0, 0.35);
  background: #fff;
  transform: rotate(-25deg);
}
.normal label:after {
  background: transparent;
  height: calc(100% + 8px);
  border-radius: 30px;
  top: -5px;
  width: calc(100% + 8px);
  left: -4px;
  z-index.........完整代码请登录后点击上方下载按钮下载查看

网友评论0