css实现checkbox点击选择三维盒子翻转动画效果代码

代码语言:html

所属分类:表单美化

代码描述:css实现checkbox点击选择三维盒子翻转动画效果代码

代码标签: 点击 选择 三维 盒子 翻转 动画 效果

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

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">


    <style>
        *,*::before,*::after{padding:0;margin:0 auto;box-sizing:border-box}body{background-color:#111;color:#fff;min-height:100vh;display:grid;place-items:center}
        @import url("https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;700&display=swap");
        *, *::before, *::after {
          box-sizing: border-box;
        }
        
        body {
          font-family: "Ubuntu", sans-serif;
          background-color: #ddd;
          color: #000;
          min-height: 100vh;
          margin: 0;
          display: grid;
          place-items: center;
          perspective: 750px;
        }
        
        *:not(:empty) {
          transform-style: preserve-3d;
        }
        
        .checkboxes {
          width: 100%;
          max-width: 420px;
        }
        
        .flipBox {
          position: relative;
          display: block;
          text-align: left;
          margin: 1em auto;
          cursor: pointer;
        }
        .flipBox:active > .flipBox_boxOuter {
          height: 25%;
        }
        .flipBox span {
          padding-left: 1.25em;
        }
        .flipBox > input {
          -webkit-appearance: none;
             -moz-appearance: none;
                  appearance: none;
          position: fixed;
          left: -100vmax;
          top: -100vmax;
        }
        .flipBox > input:checked ~ .flipBox_boxOuter {
          -webkit-animation: flipBox1 1s forwards linear;
                  animation: flipBox1 1s forwards linear;
        }
        .flipBox > input:checked ~ .flipBox_boxOuter .flipBox_box {
          -webkit-animation: flipBox2 1s forwards ease-in-out;
                  animation: flipBox2 1s forwards ease-in-out;
        }
        .flipBox > input:checked ~ .flipBox_shadow {
          -webkit-animation: flipBox3 1s forwards ease-in-out;
                  animation: flipBox3 1s forwards ease-in-out;
        }
        .flipBox > input:not(:checked) ~ .flipBox_boxOuter {
          -webkit-animation: flipBox4 1s forwards linear;
                  animation: flipBox4 1s forwards linear;
        }
        .flipBox > input:not(:checked) ~ .flipBox_boxOuter .flipBox_box {
          -webkit-animation: flipBox5 1s forwards ease-in-out;
                  animation: flipBox5 1s forwards ease-in-out;
        }
        .flipBox > input:not(:checked) ~ .flipBox_shadow {
          -webkit-animation: flipBox6 1s forwards ease-in-out;
                  animation: flipBox6 1s forwards ease-in-out;
        }
        .flipBox > input:disabled ~ * {
          cursor: not-allowed;
        }
        .flipBox > input:disabled ~ .flipBox_boxOuter {
          height: 0%;
        }
        .flipBox > input:disabled ~ .flipBox_boxOuter .flipBox_box > div:nth-child(6) {
          background-color: #ccc;
        }
        .flipBox > input:disabled ~ .flipBox_boxOuter .flipBox_box > div:nth-child(-n+5), .flipBox > input:disabled ~ .flipBox_boxOuter ~ .flipBox_shadow {
          display: none;
        }
        .flipBox > input:focus-visible ~ span {
          outline: 1px #000 solid;
          outline-offset: 0.25em;
        }
        .flipBox_boxOuter {
          position: absolute;
          left: 0;
          top: 50%;
          width: 1em;
          height: 1em;
          transform-origin: top;
          transition: height 0.25s;
        }
        .flipBox_box {
          position: absolute;
          left: 50%;
          top: 50%;
          width: 1em;
          height: 100%;
          transform: translate(-50%, -50%);
        }
        .flipBox_box > div {
          position: absolute;
          width: 1em;
          box-shadow: 0 0 0.25em #0007 inset;
        }
        .flipBox_box > div:nth-child(1) {
          background-image: linear-gradient(green, white);
          transform: rotateY(0deg) translateX(50%) rotateY(90deg);
          height: 100%;
        }
        .flipBox_box > div:nth-child(2) {
          background-image: linear-gradient(green, white);
          transform: rotateY(90deg) translateX(50%) rotateY(90deg);
          height: 100%;
        }
        .flipBox_box > div:nth-child(3) {
          background-image: linear-gradient(green, white);
          transform: rotateY(180deg) translateX(50%) rotateY(90deg);
          height: 100%;
        }
        .flipBox_box > div:nth-child(4) {
          background-image: linear-gradient(green, white);
          transform: rotateY(270deg) translateX(50%) rotateY(90deg);
          height: 100%;
        }
        .flipBox_box > div:nth-child(5) {
          background-color: green;
          transform: rotateX(90deg) translateY(-0.5em);
          transform-origin: top;
          height: 1em;
        }
        .flipBox_box > div:nth-child(5)::after {
          content: "";
          position: absolute;
          width: 100%;
          height: 100%;
          background-color: white;
          -webkit-clip-path: polygon(12.5% 56.25%, 25% 43.75%, 37.5% 56.25%, 75% 18.75%, 87.5% 31.25%, 37.5% 81.25%, 12.5% 56.25%);
                  clip-path: polygon(12.5% 56.25%, 25% 43.75%, 37.5% 56.25%, 75% 18.75%, 87.5% 31.25%, 37.5% 81.25%, 12.5% 56.25%);
        }
        .flipBox_box > div:nth-child(6) {
          bottom: 0;
          background-color: white;
          transform: rotateX(90deg) translateY(0.5em);
          transform-origin: bottom;
          height: 1em;
        }
        .flipBox_shadow {
          position: absolute;
          left: 0;
          top: 50%;
          width: 1em;
          height: 1em;
          transform: translateY(-50%) translateZ(-1px);
          background-color: #0007;
          filter: blur(0.2em);
        }
        @-webkit-keyframes flipBox1 {
          0%, 100% {
            transform: rotateX(90deg);
            -webkit-animation-timing-function: ease-out;
                    animation-timing-function: ease-out;
          }
          50% {
            transform: rotateX(90deg) translateY(2em);
            -webkit-animation-timing-function: ease-in;
                    animation-timing-function: ease-in;
          }
        }
        @keyframes flipBox1 {
          0%, 100% {
            transform: rotateX(90deg);
            -webkit-animation-timing-function: ease-out;
                    animation-timing-function: ease-out;
          }
          50% {
            transform: rotateX(90deg) translateY(2em);
            -webkit-animation-timing-function: ease-in;
                    animation-timing-function: ease-in;
          }
        .........完整代码请登录后点击上方下载按钮下载查看

网友评论0