How To Create CSS3 3D Rotation Animation Effects Only HTML And CSS

   Project Introduction: In this project, we are going to implement a car running on a track using HTML and CSS with sound effects.

File structure:

  • . index.html
  • . style.css
 HTML code:  In the following code,, first time open an index.html file then create HTML Structure. than Inside the body tag must take a <div></div> then take a class this class name anything select than create a <div> tag and this <div > inside fore <span> tag create and and save this file.

HTML Code:


<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="style.css">
    <!--font awesome filup-->
    <link rel="stylesheet" href="css/all.css">
    <title> 3D Rotation animation</title>
  <body>
    <div class="box">
      <div>
        <span></span>
        <span></span>
        <span></span>
        <span></span>

      </div>
    </div>
  </body>
</html>

style.css: The following is the code for file “style.css” which is used in the above HTML code. 

body{
  margin: 0;
  padding: 0;
  background: #02072A;
}
.box{
  position: absolute;
  top: calc(50% - 150px);
  left: calc(50% - 100px);
  transform: perspective(1000px) rotateY(-45deg);
  width: 200px;
  height: 300px;
  transform-style: preserve-3d;
}
.box::before{
  content: '';
  position: absolute;
  bottom: -100px;
  left: 0;
  width: 100%;
  height: 50px;
  background: #000;
  opacity: 0.5;
  filter: blur(40px);
  transform: rotateX(90deg);
}
.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: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(0deg, #f1f1f1, #bbb, #f1f1f1 );
  border-radius: 20px;
}
.box div span:nth-child(1){
  transform: rotateX(0deg);
}
.box div span:nth-child(2){
  transform: rotateX(45deg);
}
.box div span:nth-child(3){
  transform: rotateX(-45deg);
}
.box div span:nth-child(4){
  transform: rotateX(90deg);
}
@keyframes animate {
  0%{
    transform: perspective(1000px) rotateX(0deg);
  }
  100%{
    transform: perspective(1000px) rotateX(359deg);
  }

}

Output :  



My YouTube video:


Post a Comment

0 Comments

Ad Code

Responsive Advertisement