css3立方體效果程式碼例項

antzone發表於2017-03-13

分享一段程式碼例項,它實現了立方體效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
* {
  padding: 0;
  margin: 0;
}
.div1 {
  width: 500px;
  height: 500px;
  transform-style: preserve-3d;
  perspective-origin: center center;
  transform: rotateX(20deg) rotateY(30deg);
  position: relative;
  margin: 100px auto;
}
.div1 div {
  width: 300px;
  height: 300px;
  opacity: 0.8;
  position: absolute;
  top: 0;
}
.div1 div:nth-child(1) {
  background-color: #089efd;
  transform: rotateY(90deg) translateZ(150px);
}
.div1 div:nth-child(2) {
  background-color: #c1e2b3;
  transform: translateZ(150px);
}
.div1 div:nth-child(3) {
  background-color: #0dc392;
  transform: rotateY(90deg) translateZ(150px);
}
.div1 div:nth-child(4) {
  background-color: #a6e1ec;
  transform: translateZ(-150px);
}
.div1 div:nth-child(5) {
  background-color: #CDEC95;
  transform: rotateX(90deg) translateZ(150px);
}
.div1 div:nth-child(6) {
  background-color: #0dc392;
  transform: rotateX(-90deg) translateZ(150px);
}
</style>
</head>
<body>
  <div class="div1">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </div>
</body>
</html>

相關文章