欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

3D立方体(cube)

程序员文章站 2022-03-26 08:49:01
...

3D立方体

示例

3D立方体(cube)

html

<p>Hover the cursor on The Cube</p>
<div id='cube-container'>
  <div class="face top"></div>
  <div class="face right"></div>
  <div class="face bottom"></div>
  <div class="face left"></div>
  <div class="face back"></div>
  <div class="face front"></div>
</div>

css

body {
  margin: unset;
  height: 100vh;
  background:#171a1b;
  color:white;
  font-family:"DIN Alternate";
  text-align:center;
}
#cube-container {
  box-sizing: border-box;
  transform-style: preserve-3d;
  top: 50%;
  left: 50%;
  position: relative;
  width: 250px;
  height: 250px;
  transition: 2s cubic-bezier(.68,-0.55,.27,1.55);//backword ease-in-out courtesy of firefox dev tools
  transform: translate(-50%, -50%);
  .face {
    width: 250px;
    height: 250px;
    position: absolute;
    border: 2px solid #ed3403;
    background:#ed340370;
    box-shadow: 0px 0px 150px #ed3403;
    &.top {
      transform: rotateX(90deg);
      margin-top: -50%;
    }
    &.right {
      transform: rotateY(90deg);
      margin-left: 50%;
    }
    &.left {
      transform: rotateY(-90deg);
      margin-left: -50%;
    }
    &.bottom {
      transform: rotateX(90deg);
      margin-top: 50%;
    }
    &.back {
      transform: translateZ(125px);
    }
    &.front {
      transform: translateZ(-125px);
    }
  }
  &:hover {
    transform: rotateX(-25deg) rotateY(-40deg) translate(-50%, -50%);
    transition: 2s cubic-bezier(.68,-0.55,.27,1.55);//backword ease-in-out courtesy of firefox dev tools
  }
}
//glow idea inspired by https://xhz.bos.xyz