正方体
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style type="text/css">
  7. body{
  8. overflow: hidden;
  9. }
  10. .box {
  11. width: 300px;
  12. height: 300px;
  13. position: relative;
  14. top: 0;
  15. bottom: 0;
  16. left: 0;
  17. right: 0;
  18. margin: 200px auto;
  19. transform-style: preserve-3d;
  20. /* -webkit-perspective: 250; */
  21. text-align: center;
  22. animation:move 7s linear infinite;
  23. }
  24. .box div {
  25. width: 100%;
  26. height: 100%;
  27. position: absolute;
  28. font: 50px/300px "微软雅黑";
  29. transition: all .8s;
  30. background-size: 100% 100%;
  31. opacity: 0.7;
  32. text-align: center;
  33. }
  34. @keyframes move{
  35. from {transform:rotateX(0deg) rotateY(0deg);}
  36. to {transform:rotateX(360deg) rotateY(360deg)}
  37. }
  38. .box div:nth-child(1) {
  39. background: linear-gradient(#00FFFF,rgba(255,255,255,0.5));
  40. transform: translateZ(150px);
  41. box-shadow: 0 0 10px deepskyblue;
  42. }
  43. .box div:nth-child(2) {
  44. background: linear-gradient(#00FFFF,rgba(255,255,255,0.5));
  45. transform: rotateY(90deg) translateZ(150px);
  46. box-shadow: 0 0 10px deepskyblue;
  47. }
  48. .box div:nth-child(3){
  49. background: linear-gradient(#00FFFF,rgba(255,255,255,0.5));
  50. transform: rotateY(180deg) translateZ(150px);
  51. box-shadow: 0 0 10px deepskyblue;
  52. }
  53. .box div:nth-child(4) {
  54. background: linear-gradient(#00FFFF,rgba(255,255,255,0.5));
  55. transform: rotateY(270deg) translateZ(150px);
  56. box-shadow: 0 0 10px deepskyblue;
  57. }
  58. .box div:nth-child(5) {
  59. background: linear-gradient(#00FFFF,rgba(255,255,255,0.5));
  60. transform: rotateX(90deg) translateZ(150px);
  61. box-shadow: 0 0 10px deepskyblue;
  62. }
  63. .box div:nth-child(6) {
  64. background: linear-gradient(#00FFFF,rgba(255,255,255,0.5));
  65. transform: rotateX(270deg) translateZ(150px);
  66. box-shadow: 0 0 10px deepskyblue;
  67. }
  68. .box:hover div:nth-child(1){
  69. transform: translateZ(300px);
  70. }
  71. .box:hover div:nth-child(2){
  72. transform:rotateY(90deg) translateZ(300px);
  73. }
  74. .box:hover div:nth-child(3){
  75. transform:rotateY(180deg) translateZ(300px);
  76. }
  77. .box:hover div:nth-child(4){
  78. transform:rotateY(270deg) translateZ(300px);
  79. }
  80. .box:hover div:nth-child(5){
  81. transform:rotateX(90deg) translateZ(300px);
  82. }
  83. .box:hover div:nth-child(6){
  84. transform:rotateX(270deg) translateZ(300px);
  85. }
  86. </style>
  87. </head>
  88. <body>
  89. <div class="box">
  90. <div>正前面</div>
  91. <div>右面</div>
  92. <div>正后面</div>
  93. <div>左面</div>
  94. <div>上面</div>
  95. <div>下面</div>
  96. </div>
  97. </body>
  98. </html>

双层的立方体
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>3D炫酷相册</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. }
  12. :root,
  13. body {
  14. height: 100%;
  15. width: 100%;
  16. background-color: black;
  17. }
  18. /* 最外层容器样式 */
  19. .container {
  20. width: 200px;
  21. height: 200px;
  22. position: absolute;
  23. perspective: 2000px;
  24. /* 调整视距 */
  25. top: calc(50% - 100px);
  26. left: calc(50% - 100px);
  27. /* 垂直水平居中 */
  28. }
  29. /*立方体容器样式*/
  30. .cube {
  31. width: 200px;
  32. height: 200px;
  33. transform-style: preserve-3d;
  34. transform: rotateX(-30deg) rotateY(-80deg);
  35. animation: roddy 10s linear infinite;
  36. /*设置动画匀速重复*/
  37. }
  38. @keyframes roddy {
  39. 0% {
  40. transform: rotateX(0deg) rotateY(0deg);
  41. }
  42. 100% {
  43. transform: rotateX(360deg) rotateY(360deg);
  44. }
  45. }
  46. .cube div {
  47. position: absolute;
  48. width: 200px;
  49. height: 200px;
  50. opacity: 0.8;
  51. /* 设置透明度 */
  52. transition: all 0.4s;
  53. /* 过渡动画 */
  54. }
  55. /* 外面照片大小设置 */
  56. .out_pic {
  57. width: 200px;
  58. height: 200px;
  59. }
  60. .cube .out_front {
  61. transform: rotateY(0deg) translateZ(100px);
  62. }
  63. .cube .out_back {
  64. transform: rotateY(180deg) translateZ(100px);
  65. }
  66. .cube .out_left {
  67. transform: rotateY(90deg) translateZ(100px);
  68. }
  69. .cube .out_right {
  70. transform: rotateY(-90deg) translateZ(100px);
  71. }
  72. .cube .out_top {
  73. transform: rotateX(90deg) translateZ(100px);
  74. }
  75. .cube .out_bottom {
  76. transform: rotateX(-90deg) translateZ(100px);
  77. }
  78. .cube #small {
  79. position: absolute;
  80. width: 100px;
  81. height: 100px;
  82. top: 50px;
  83. left: 50px;
  84. }
  85. /* 里面照片大小设置 */
  86. .in_pic {
  87. width: 100px;
  88. height: 100px;
  89. }
  90. .cube .in_front {
  91. transform: rotateY(0deg) translateZ(50px);
  92. }
  93. .cube .in_back {
  94. transform: rotateY(180deg) translateZ(50px);
  95. }
  96. .cube .in_left {
  97. transform: rotateY(90deg) translateZ(50px);
  98. }
  99. .cube .in_right {
  100. transform: rotateY(-90deg) translateZ(50px);
  101. }
  102. .cube .in_top {
  103. transform: rotateX(90deg) translateZ(50px);
  104. }
  105. .cube .in_bottom {
  106. transform: rotateX(-90deg) translateZ(50px);
  107. }
  108. /*鼠标移入后样式*/
  109. .cube:hover .out_front {
  110. transform: rotateY(0deg) translateZ(200px);
  111. }
  112. .cube:hover .out_back {
  113. transform: rotateY(180deg) translateZ(200px);
  114. }
  115. .cube:hover .out_left {
  116. transform: rotateY(90deg) translateZ(200px);
  117. }
  118. .cube:hover .out_right {
  119. transform: rotateY(-90deg) translateZ(200px);
  120. }
  121. .cube:hover .out_top {
  122. transform: rotateX(90deg) translateZ(200px);
  123. }
  124. .cube:hover .out_bottom {
  125. transform: rotateX(-90deg) translateZ(200px);
  126. }
  127. </style>
  128. </head>
  129. <body>
  130. <div class="container">
  131. <div class="cube">
  132. <!-- 外面立方体开始 -->
  133. <div class="out_front">
  134. <img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
  135. class="out_pic" />
  136. </div>
  137. <div class="out_back">
  138. <img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
  139. class="out_pic" />
  140. </div>
  141. <div class="out_left">
  142. <img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
  143. class="out_pic" />
  144. </div>
  145. <div class="out_right">
  146. <img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
  147. class="out_pic" />
  148. </div>
  149. <div class="out_top">
  150. <img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
  151. class="out_pic" />
  152. </div>
  153. <div class="out_bottom">
  154. <img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
  155. class="out_pic" />
  156. </div>
  157. <!-- 外面立方体结束 -->
  158. <!-- 里面立方体开始 -->
  159. <div class="in_front" id="small">
  160. <img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
  161. class="in_pic" />
  162. </div>
  163. <div class="in_back" id="small">
  164. <img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
  165. class="in_pic" />
  166. </div>
  167. <div class="in_left" id="small">
  168. <img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
  169. class="in_pic" />
  170. </div>
  171. <div class="in_right" id="small">
  172. <img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
  173. class="in_pic" />
  174. </div>
  175. <div class="in_top" id="small">
  176. <img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
  177. class="in_pic" />
  178. </div>
  179. <div class="in_bottom" id="small">
  180. <img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
  181. class="in_pic" />
  182. </div>
  183. <!-- 里面立方体结束 -->
  184. </div>
  185. </div>
  186. </body>
  187. </html>