CSS3 3D方块效果代码

快乐打工仔 分类:实例代码

CSS3 3D方块效果代码属于前端实例代码,有关更多实例代码大家可以查看

分享一段代码实例,它利用css3实现了3D方块效果。

代码实例如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.pipipi.net/" />
<title>犀牛前端部落</title>
<style>
.wrap {
  width: 100px;
  height: 100px;
  padding: 100px;
  border: 5px solid #000;
  margin: 100px auto;
  perspective: 600px;
}
.box {
  width: 100px;
  height: 100px;
  background: red;
  position: relative;
  transform-style: preserve-3d;
  transition: 2s;
  transform-origin: center center -50px;
}
.box div {
  width: 100px;
  height: 100px;
  position: absolute;
  color: #fff;
  font-size: 50px;
  text-align: center;
  line-height: 100px;
}
.box div:nth-of-type(1) {
  left: 0;
  top: -100px;
  background: #9C0;
  transform-origin: bottom;
  transform: rotateX(90deg);
}
.box div:nth-of-type(2) {
  left: -100px;
  top: 0;
  background: #CF3;
  transform-origin: right;
  transform: rotateY(-90deg);
}
.box div:nth-of-type(3) {
  left: 0;
  top: 0;
  background: #CCF;
}
.box div:nth-of-type(4) {
  left: 100px;
  top: 0;
  background: #0C9;
  transform-origin: left;
  transform: rotateY(90deg);
}
.box div:nth-of-type(5) {
  left: 0;
  top: 100px;
  background: #69C;
  transform-origin: top;
  transform: rotateY(-90deg);
}
.box div:nth-of-type(6) {
  left: 0;
  top: 0;
  background: #F0C;
  transform: translateZ(-100px);
}
.wrap:hover .box {
  transform: translateZ(-100px) rotateX(180deg);
}
</style>
</head>
<body>
  <div class="wrap">
    <div class="box">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
      <div>6</div>
    </div>
  </div>
</body>
</html>

CSS3 3D方块效果代码,这样的场景在实际项目中还是用的比较多的,关于CSS3 3D方块效果代码就介绍到这了。

回复

我来回复
  • 暂无回复内容