练习3_旋转立方体.html 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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>Document</title>
  7. <style>
  8. body{
  9. background-color: #000;
  10. perspective: 1000px;
  11. perspective-origin: center center;
  12. }
  13. .box{
  14. width: 400px;
  15. height: 400px;
  16. border:1px dashed white;
  17. margin:100px auto;
  18. position: relative;
  19. transform-style: preserve-3d;
  20. animation: foo 6s linear infinite;
  21. }
  22. @keyframes foo {
  23. from{
  24. transform: rotateY(0);
  25. }
  26. to{
  27. transform: rotateY(360deg);
  28. }
  29. }
  30. .box div{
  31. width: 400px;
  32. height: 400px;
  33. background-color: rgba(255,255,255,0.5);
  34. font-size: 50px;
  35. font-weight: bold;
  36. text-align: center;
  37. line-height: 400px;
  38. position: absolute;
  39. top: 0;
  40. left: 0;
  41. }
  42. .face1{
  43. transform: translateZ(200px);
  44. }
  45. .face2{
  46. transform: translateZ(-200px);
  47. }
  48. .face3{
  49. transform: rotateY(90deg) translateZ(200px);
  50. }
  51. .face4{
  52. transform: rotateY(-90deg) translateZ(200px);
  53. }
  54. .face5{
  55. transform: rotateX(90deg) translateZ(200px);
  56. }
  57. .face6{
  58. transform: rotateX(-90deg) translateZ(200px);
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <div class="box">
  64. <div class="face1">1</div>
  65. <div class="face2">2</div>
  66. <div class="face3">3</div>
  67. <div class="face4">4</div>
  68. <div class="face5">5</div>
  69. <div class="face6">6</div>
  70. </div>
  71. </body>
  72. </html>