当前位置:   article > 正文

纯css实现3D立方体_css 立体div

css 立体div

   关注公众号,每天都能领外卖红包

纯css实现3D立方体特效,通过3D旋转和平移原理实现,话不多说直接贴代码

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. body,html{
  5. margin: 0;
  6. }
  7. body{
  8. display: flex;
  9. align-items: center;
  10. }
  11. #parent{
  12. margin: 0 auto;
  13. width: 300px;
  14. height: 300px;
  15. position: relative;
  16. transform: rotate(45deg);
  17. transform-style: preserve-3d;
  18. animation: 10s spin linear infinite;
  19. transition: transform 1s linear;
  20. }
  21. #parent_new{
  22. left: calc(50% - 75px);
  23. width: 150px;
  24. height: 150px;
  25. position: absolute;
  26. transform: rotate(45deg) ;
  27. transform-style: preserve-3d;
  28. animation: 3s spin_new linear infinite;
  29. transition: transform 0.5s linear;
  30. }
  31. #parent>div{
  32. width: 300px;
  33. height: 300px;
  34. position: absolute;
  35. border: 5px solid #ccc;
  36. }
  37. #parent_new>div{
  38. width: 150px;
  39. height: 150px;
  40. position: absolute;
  41. border: 1px solid #ccc;
  42. background: black;
  43. opacity: 0.5;
  44. }
  45. #parent>div:nth-child(1){
  46. transform: translateZ(-150px);
  47. transition: transform 1s linear;
  48. }
  49. #parent>div:nth-child(2){
  50. transform:rotateY(-90deg) translateZ(150px) ;
  51. transition: transform 1s linear;
  52. }
  53. #parent>div:nth-child(3){
  54. transform:rotateY(-90deg) translateZ(-150px) ;
  55. transition: transform 1s linear;
  56. }
  57. #parent>div:nth-child(4){
  58. transform:rotateX(90deg) translateZ(150px) ;
  59. transition: transform 1s linear;
  60. }
  61. #parent>div:nth-child(5){
  62. transform:rotateX(90deg) translateZ(-150px) ;
  63. transition: transform 1s linear;
  64. }
  65. #parent>div:nth-child(6){
  66. transform: translateZ(150px);
  67. }
  68. #parent_new>div:nth-child(1){
  69. transform: translateZ(-75px);
  70. transition: transform 1s linear;
  71. }
  72. #parent_new>div:nth-child(2){
  73. transform:rotateY(-90deg) translateZ(75px) ;
  74. transition: transform 1s linear;
  75. }
  76. #parent_new>div:nth-child(3){
  77. transform:rotateY(-90deg) translateZ(-75px) ;
  78. transition: transform 1s linear;
  79. }
  80. #parent_new>div:nth-child(4){
  81. transform:rotateX(90deg) translateZ(75px) ;
  82. transition: transform 1s linear;
  83. }
  84. #parent_new>div:nth-child(5){
  85. transform:rotateX(90deg) translateZ(-75px) ;
  86. transition: transform 1s linear;
  87. }
  88. #parent_new>div:nth-child(6){
  89. transform: translateZ(75px);
  90. }
  91. @keyframes spin{
  92. 0%{
  93. transform: rotateX(0deg) rotateY(0deg);
  94. }
  95. 100%{
  96. transform: rotateX(360deg) rotateY(360deg);
  97. }
  98. }
  99. @keyframes spin_new{
  100. 0%{
  101. transform: rotateX(0deg) rotateY(0deg);
  102. }
  103. 100%{
  104. transform: rotateX(360deg) rotateY(360deg);
  105. }
  106. }
  107. </style>
  108. </head>
  109. <body>
  110. <!--外层立方体-->
  111. <div id="parent">
  112. <div></div>
  113. <div></div>
  114. <div></div>
  115. <div></div>
  116. <div></div>
  117. <div></div>
  118. </div>
  119. <!--内层立方体-->
  120. <div id="parent_new">
  121. <div></div>
  122. <div></div>
  123. <div></div>
  124. <div></div>
  125. <div></div>
  126. <div></div>
  127. </div>
  128. </body>
  129. </html>

效果图

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/96663
推荐阅读
相关标签
  

闽ICP备14008679号