Here's a single HTML file containing CSS and JavaScript that creates an animated weather card display with four weather conditions (wind, rain, sun, snow) shown side by side:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Animated Weather Cards</title>
<style>
body {
margin: 0;
padding: 20px;
background-color: #121212;
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
}
h1 {
color: #f0f0f0;
margin-bottom: 30px;
}
.weather-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 20px;
width: 100%;
max-width: 1200px;
}
.weather-card {
position: relative;
width: 250px;
height: 350px;
background-color: #1e1e1e;
border-radius: 15px;
overflow: hidden;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
color: white;
padding: 20px;
box-sizing: border-box;
}
.weather-title {
font-size: 24px;
margin-bottom: 10px;
text-align: center;
z-index: 2;
position: relative;
}
/* Wind animations */
.wind-cloud {
position: absolute;
width: 60px;
height: 30px;
background-color: #4a4a4a;
border-radius: 20px;
opacity: 0.8;
animation: windMove 8s linear infinite;
}
.wind-cloud:nth-child(2) {
top: 80px;
left: 30px;
width: 80px;
height: 40px;
animation-delay: -2s;
}
.wind-cloud:nth-child(3) {
top: 150px;
left: 100px;
width: 70px;
height: 35px;
animation-delay: -4s;
}
.tree {
position: absolute;
bottom: 30px;
width: 20px;
height: 80px;
background-color: #5e3a1e;
border-radius: 5px;
}
.tree::before {
content: '';
position: absolute;
top: -30px;
left: -20px;
width: 60px;
height: 60px;
background-color: #2a5c2a;
border-radius: 50%;
}
.tree:nth-child(4) {
left: 50px;
animation: swayLeft 3s ease-in-out infinite alternate;
}
.tree:nth-child(5) {
left: 150px;
animation: swayRight 3.5s ease-in-out infinite alternate;
}
@keyframes windMove {
0% { transform: translateX(-100px); }
100% { transform: translateX(300px); }
}
@keyframes swayLeft {
0% { transform: rotate(-5deg); }
100% { transform: rotate(5deg); }
}
@keyframes swayRight {
0% { transform: rotate(5deg); }
100% { transform: rotate(-5deg); }
}
/* Rain animations */
.raindrop {
position: absolute;
width: 2px;
height: 10px;
background-color: #6ba3d6;
border-radius: 0 0 5px 5px;
animation: rainFall linear infinite;
}
.puddle {
position: absolute;
bottom: 20px;
width: 40px;
height: 10px;
background-color: rgba(107, 163, 214, 0.5);
border-radius: 50%;
animation: puddleGrow 4s ease-out infinite;
}
.puddle:nth-child(2) {
left: 80px;
animation-delay: 1s;
}
.puddle:nth-child(3) {
left: 160px;
animation-delay: 2s;
}
@keyframes rainFall {
0% { transform: translateY(-20px); opacity: 1; }
80% { opacity: 1; }
100% { transform: translateY(300px); opacity: 0; }
}
@keyframes puddleGrow {
0% { transform: scale(0.2); opacity: 0; }
50% { opacity: 0.7; }
100% { transform: scale(1); opacity: 0; }
}
/* Sun animations */
.sun {
position: absolute;
top: 50px;
left: 50%;
transform: translateX(-50%);
width: 80px;
height: 80px;
background-color: #ffde59;
border-radius: 50%;
box-shadow: 0 0 40px #ffde59;
}
.sun-ray {
position: absolute;
top: 50%;
left: 50%;
width: 5px;
height: 40px;
background-color: #ffde59;
transform-origin: top center;
animation: sunShine 4s linear infinite;
}
@keyframes sunShine {
0% { opacity: 0.3; }
50% { opacity: 0.8; }
100% { opacity: 0.3; }
}
/* Snow animations */
.snowflake {
position: absolute;
width: 5px;
height: 5px;
background-color: white;
border-radius: 50%;
filter: blur(1px);
animation: snowFall linear infinite;
}
.snow-accumulation {
position: absolute;
bottom: 0;
width: 100%;
height: 20px;
background-color: rgba(255, 255, 255, 0.7);
border-radius: 0 0 15px 15px;
animation: snowGrow 10s linear infinite;
}
@keyframes snowFall {
0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
100% { transform: translateY(300px) rotate(360deg); opacity: 0; }
}
@keyframes snowGrow {
0% { height: 0; }
50% { height: 20px; }
100% { height: 0; }
}
/* Controls */
.controls {
margin-top: 30px;
display: flex;
gap: 15px;
}
button {
padding: 10px 20px;
background-color: #333;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #555;
}
button.active {
background-color: #0078d7;
}
</style>
</head>
<body>
<h1>Animated Weather Cards</h1>
<div class="weather-container">
<!-- Wind Card -->
<div class="weather-card" id="wind-card">
<h2 class="weather-title">Windy</h2>
<div class="wind-cloud"></div>
<div class="wind-cloud"></div>
<div class="wind-cloud"></div>
<div class="tree"></div>
<div class="tree"></div>
</div>
<!-- Rain Card -->
<div class="weather-card" id="rain-card">
<h2 class="weather-title">Rainy</h2>
<div class="puddle"></div>
<div class="puddle"></div>
<div class="puddle"></div>
</div>
<!-- Sun Card -->
<div class="weather-card" id="sun-card">
<h2 class="weather-title">Sunny</h2>
<div class="sun"></div>
</div>
<!-- Snow Card -->
<div class="weather-card" id="snow-card">
<h2 class="weather-title">Snowy</h2>
<div class="snow-accumulation"></div>
</div>
</div>
<div class="controls">
<button onclick="toggleAnimation('wind')">Toggle Wind</button>
<button onclick="toggleAnimation('rain')">Toggle Rain</button>
<button onclick="toggleAnimation('sun')">Toggle Sun</button>
<button onclick="toggleAnimation('snow')">Toggle Snow</button>
</div>
<script>
// Create dynamic elements