6_CSS33D效果.html 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /* 设置观众视角 */
  10. /* 视角的距离 */
  11. perspective: 1000px;
  12. /* 视角的位置 */
  13. perspective-origin: center center;
  14. }
  15. .box,.div1,.div2{
  16. width: 200px;
  17. height: 200px;
  18. }
  19. .box{
  20. border:1px dashed black;
  21. position: relative;
  22. margin: 100px auto;
  23. /* 使其内部元素的变形为3D效果 */
  24. transform-style: preserve-3d;
  25. }
  26. .div1,.div2{
  27. position: absolute;
  28. top: 0;
  29. left: 0;
  30. transition: all 3s;
  31. }
  32. .div1{
  33. background-color: red;
  34. }
  35. .div2{
  36. background-color: blue;
  37. }
  38. .box:hover .div2{
  39. transform: rotateY(180deg) translateZ(20px);
  40. }
  41. .box:hover .div1{
  42. transform: rotateY(180deg) translateZ(1px);
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <div class="box">
  48. <div class="div1"></div>
  49. <div class="div2"></div>
  50. </div>
  51. </body>
  52. </html>