Solution: Running Car Animation using HTML & CSS with source code, demo, and also how you can execute full program easily. To complete the program you need to follow those steps given bellow
Live Demo
Also Helpful –
Running Car Animation using HTML & CSS
Description
Back to coding, To complete this program with debugging free code you have to create two files. The first file is to HTML and the second file gonna be CSS for the style part,
index.html
Create an HTML file named ‘index.html‘ and put those codes given below.
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 |
<!-- Coding Debugging (https://codingdebugging.com) --> <!DOCTYPE html> <html> <head> <title>Running Car Animation - Coding Debugging</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- My Stylesheet --> <link rel="stylesheet" href="style.css"> </head> <body> <div class="highway"> <div class="road"></div> <div class="city"></div> <div class="car"> <img src="include/car.png" alt="car.png"> <div class="wheels"> <div class="wheel front-wheel"></div> <div class="wheel back-wheel"></div> </div> </div> </div> </body> </html> |
style.css
Create a CSS file named ‘style.css‘ and put those codes given below.
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
* { margin: 0; padding: 0; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; } body { overflow: hidden; } .highway { height: 100vh; background-image: url("include/sky.jpg"); background-position: center; background-size: cover; overflow: hidden; } .road { position: absolute; bottom: 0; left: 0; right: 0; width: 500%; height: 400px; background-image: url("include/road.jpg"); background-size: cover; animation: road 2s linear infinite; } @keyframes road { to { transform: translateX(-2800px); } } .city { position: absolute; bottom: 0; left: 0; right: 0; width: 500%; bottom: 400px; height: 200px; background-image: url("include/city.png"); animation: city 12s linear infinite; } @keyframes city { to { transform: translateX(-2000px); } } .car { position: absolute; bottom: 0; left: 0; right: 0; width: 500%; left: 20%; bottom: 20px; transform: translateX(-20%); width: 400px; height: 400px; animation: car 1s linear infinite; } img { max-width: 100%; max-height: 100%; } @keyframes car { 0% { transform: translateY(-1px); } 50% { transform: translateY(1px); } 100% { transform: translateY(-1px); } } .wheel { position: absolute; bottom: 0; left: 0; right: 0; width: 500%; bottom: 240px; width: 80px; height: 80px; background-image: url("include/wheel.png"); background-position: center; background-size: cover; animation: wheel 1s linear infinite; } .front-wheel { left: 278px; } .back-wheel { left: 32px; } @keyframes wheel { to { transform: rotate(360deg); } } @media screen and (max-width: 800px) { @keyframes road { to { transform: translateX(-1800px); } } } |
Thank you for visiting!
We appreciate you for your precious time. I hope you are learn something from here! If you have any queries about this coding comment down below we will reply ASAP.
Keep coding, Keep debugging!