Create an animated greeting card using CSS animations
Hey, I am Ajink and today in this blog, we’re going to create an animated greeting card using CSS animations.
HTML Code: create a index.html file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Animated Greeting Card</title>
</head>
<body>
<div class="card">
<div class="greeting">Happy New Year!</div>
<div class="fireworks"></div>
</div>
</body>
</html>
HTML Code Explanation:
- We start with a basic HTML structure, linking to an external stylesheet (
style.css) . - Inside the
bodytag, we have adivwith the classcardthat contains two child elements: one for the greeting message and another for the animated fireworks.
CSS Code: create a style.css
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
.card {
position: relative;
width: 300px;
height: 200px;
border: 2px solid #ccc;
border-radius: 10px;
overflow: hidden;
}
.greeting {
text-align: center;
font-size: 18px;
padding: 20px;
background-color: #3498db;
color: #fff;
}
.fireworks {
position: absolute;
width: 100%;
height: 100%;
background-image: url('https://gallery.yopriceville.com/var/resizes/Free-Clipart-Pictures/Fireworks/Red_Firework_PNG_Transparent_Clipart.png?m=1610454539');
background-size: cover;
animation: fireworksAnimation 4s infinite;
opacity: 0.8;
}
@keyframes fireworksAnimation {
0%, 100% {
transform: scale(1);
}
50% {
transform: scale(1.1);
}
}
CSS Code Explanation:
- The CSS starts by setting up the overall styling. The
bodyis styled to be a flex container, centering its content both vertically and horizontally. - The
cardclass represents the greeting card. It has a defined size, rounded corners, and a border. - The
greetingclass styles the message, giving it a centered position, specific font size, padding, and background color. - The
fireworksclass sets the background image to ‘fireworks.png’ and applies a CSS animation namedfireworksAnimationto create the animated effect.
Conclusion:
In this blog, we successfully created an animated greeting card using HTML, CSS, and a touch of JavaScript for animation. You can customize the message and background image to suit different occasions. Don’t forget to subscribe to my YouTube channel at youtube.com/@ajink21 for more exciting tutorials.
More in 21 days of HTML CSS JS
See all →- Ultimate Guide to Free Web Development Resources In today’s digital age, web development is a crucial skill that opens up numerous opportunities. Whether you’re a beginner looking to build...
- 10 Effective Ways to Center a Div Hello, myself Ajink. In this article, we will explore the various techniques to center a div element on a web page. Centering a div might se...
- Learn HTML HTML Document Structure: : Defines the root of an HTML document. : Contains meta-information about the document. : Sets the title of the doc...
- How to Create an Valentine’s Day Website? How to Create an Valentine’s Day Website , lets get started Demo : Here is Complete SourceCode : body background-color: #fde8e8; font-family...
- Create a accordion with html css and javascript body { font-family: 'Arial', sans-serif; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh;...
- Create a virtual keyboard that users can interact with on the webpage. Virtual Keyboard body font-family: 'Arial', sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center;...