Hello Coders, here is the another interesting thing using CSS transform,
See below,
3D Box Rotation using Transform CSS
Source:
Rotation.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<!DOCTYPE html> <html> <head> <title>Rotation</title> <link rel="stylesheet" type="text/css" href="rotation.css"> </head> <body> <div class="box"> <div> <span></span> <span></span> <span></span> <span></span> </div> </div> </body> </html> |
Rotation.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
body{ margin: 0; padding: 0; background: #03a9f4; } .box{ position: absolute; top: calc(50% - 150px); left: calc(50% - 150px); height: 300px; width: 300px; //See here how thats work and change according to you for magical difference transform-style: preserve-3d; transform: perspective(1000px) rotateX(-10deg); } .box div{ position: absolute; top: 0; left: 0; width: 100%; height: 100%; transform-style: preserve-3d; animation: animate 5s linear infinite; } .box div span{ position: absolute; top: 100px; left: 100px; display: block; width: 70%; height: 70%; background: linear-gradient(#ffffff, #a7a7a7, #ffffff); } .box:before{ content: ''; position: absolute; bottom: -150px; left: 0; width: 100%; height: 50%; background:#000; filter: blur(40px); opacity: 0.25; } .box div span:nth-child(1){ transform: rotateX(0deg); } .box div span:nth-child(2){ transform: rotateY(90deg); } .box div span:nth-child(3){ transform: rotateX(270deg); } .box div span:nth-child(4){ transform: rotateX(90deg); } @keyframes animate{ 0%{ transform: perspective(1000px) rotateY(0deg); } 100%{ transform: perspective(1000px) rotateY(360deg); } } |
Was this article helpful?
YesNo