Introduction:
In the world of web development, CSS animations have become a powerful tool to enhance user experience and engage visitors. In this tutorial, we’ll dive into the fascinating realm of CSS animations by creating a CSS Crow animation. By the end of this tutorial, you’ll have a clear understanding of how to create engaging animations that can breathe life into your web projects.
Things You Will Learn:
- Creating a container and positioning it on the screen.
- Using keyframes to define animation stages.
- Animating elements using transforms and properties like
top
,left
, androtate
. - Adding depth with the
perspective
property. - Crafting intricate shapes using border-radius.
Video Tutorial:
Prefer watching and learning? We’ve got you covered! If you’d like to follow along with a detailed video tutorial, head over to my YouTube channel. In the video, you’ll find a step-by-step guide to creating this playful crow animation using CSS. I’ll walk you through each animation stage, provide insights into the key techniques used, and give you a visual demonstration of how to bring your web elements to life. Don’t forget to like, comment, and subscribe for more exciting web development content! Watch the full video here:
Project Folder Structure:
To get started, create a folder structure for your project:
- index.html
- style.css
HTML:
The HTML file contains the bare bones structure of our crow:
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Crow Animation</title> <!-- Stylesheet --> <link rel="stylesheet" href="style.css" /> </head> <body> <div class="container"> <div class="beak-upper"></div> <div class="beak-lower"></div> <div class="leg-1"></div> <div class="leg-2"></div> <div class="crow"> <div class="wings"> <div class="wing"></div> </div> <div class="tail"></div> </div> </div> </body> </html>
CSS:
The CSS file, style.css
, holds the enchanting animations that bring our crow to life. In this file, we define keyframes, transform properties, and more to create a captivating visual experience. The crow’s movement, wings flapping, and even blinking eyes are all achieved through a series of carefully crafted animations.
* { padding: 0; margin: 0; box-sizing: border-box; } body { background-color: #9393f5; } .container { height: 20em; width: 25em; position: absolute; transform: translate(-50%, -50%); left: 50%; top: 50%; animation: fly 2s infinite; } @keyframes fly { 50% { top: calc(50% + 3.12em); } } .crow { position: absolute; height: 5em; width: 12.5em; background-color: #000000; border-radius: 0 0 0 5em; transform: translate(-50%, -50%); left: 50%; top: 50%; perspective: 31.25em; } .crow:before { position: absolute; content: ''; height: 0.9em; width: 0.9em; background-color: #000000; box-shadow: -0.18em 0 0 0.25em #ffffff; border-radius: 50%; top: 0.9em; right: 2.5em; animation: blink 3s infinite; } @keyframes blink { 5% { transform: scaleY(0); } 10% { transform: scaleY(1); } } .crow:after { position: absolute; content: ''; height: 0.9em; width: 0.9em; background-color: #000000; box-shadow: 0.18em 0 0 0.25em #ffffff; border-radius: 50%; top: 0.9em; right: 1.5em; animation: blink 3s infinite; } .beak-upper { position: absolute; height: 3.75em; width: 5em; background-color: #623193; top: 7.5em; left: 18.12em; border-radius: 0 3.75em 0 0; animation: caw-1 2s infinite; transform-origin: 0 50%; } @keyframes caw-1 { 20% { transform: rotate(-15deg); } 30% { transform: rotate(0); } 40% { transform: rotate(-15deg); } 60% { transform: rotate(0deg); } } .beak-lower { position: absolute; height: 1.25em; width: 5em; background-color: #623193; left: 18.12em; top: 11.25em; border-radius: 0 0 1.25em 0; animation: caw-2 2s infinite; transform-origin: 0 50%; } @keyframes caw-2 { 20% { transform: rotate(15deg); } 30% { transform: rotate(0); } 40% { transform: rotate(15deg); } 60% { transform: rotate(0deg); } } .wings { position: absolute; top: 0.93em; left: 6.25em; animation: flap 2s infinite; transform-style: preserve-3d; } @keyframes flap { 50% { transform: rotateX(180deg); } } .wing { position: absolute; height: 8.12em; background-color: #310062; width: 1.25em; border-radius: 0 1.25em 1.25em 1.25em; } .wing:before { content: ''; position: absolute; height: 7.5em; width: 1.25em; background-color: #310062; border-radius: 0 0 1.25em 1.25em; right: 1.25em; } .wing:after { position: absolute; content: ''; height: 6.87em; background-color: #310062; width: 1.25em; border-radius: 1.25em 0 1.25em 1.25em; right: 2.3em; } .tail { height: 1.25em; width: 3.12em; background-color: #000000; position: absolute; left: -1.87em; top: 0.31em; border-radius: 1.25em; transform: rotate(-5deg); animation: wiggle 0.6s infinite; } @keyframes wiggle { 50% { transform: rotate(5deg); } } .tail:before, .tail:after { position: absolute; content: ''; height: 1.25em; width: 3.12em; background-color: #000000; border-radius: 1.25em; transform-origin: right; } .tail:before { transform: rotate(35deg); } .tail:after { transform: rotate(-35deg); } .leg-1, .leg-2 { position: absolute; height: 5em; width: 1.25em; top: 9.37em; transform: rotate(30deg); animation: leg 2s infinite; } @keyframes leg { 50% { transform: rotate(40deg); } } .leg-1 { background-color: #310062; left: 8.75em; } .leg-2 { background-color: #623193; left: 8.12em; } .leg-1:before, .leg-2:before { position: absolute; content: ''; height: 1.25em; width: 0.62em; background-color: transparent; border-radius: 0 1.87em 1.87em 0; top: 4.06em; right: -0.31em; } .leg-1:before { border: 0.93em solid #310062; border-left: none; } .leg-2:before { border: 0.93em solid #623193; border-left: none; }
Conclusion:
In this tutorial, we delved into the captivating world of CSS animations by dissecting a remarkable crow animation. Through the power of keyframes, transformations, and creative use of pseudo-elements, we’ve managed to create an engaging and visually stunning crow that seems to come alive on the screen.
Is such preaty