Below is an all-in-one HTML file that meets the brief. In this example there is a “dynamic” weather card at the top with four buttons that let you switch its weather animations (wind, rain, sun, snow). Below that, the four preset weather cards are displayed side by side. (You can copy and paste the code into a file and open it in your browser.)
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Animated Weather Cards</title>
<style>
/* Global styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #121212;
color: #fff;
font-family: sans-serif;
text-align: center;
padding: 20px;
}
h1 {
margin-bottom: 20px;
}
/* Container for the dynamic card and buttons */
#dynamicSection {
margin-bottom: 40px;
}
/* Weather card base styling */
.weather-card {
position: relative;
overflow: hidden;
width: 200px;
height: 200px;
margin: 10px;
border: 2px solid rgba(255, 255, 255, 0.3);
border-radius: 10px;
background-color: #1d1d1d;
}
/* Container for preset cards */
.cards-container {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 10px;
}
/* Button styles */
#weatherButtons {
margin-top: 10px;
}
#weatherButtons button {
background: #333;
color: #fff;
border: none;
padding: 8px 12px;
margin: 5px;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s ease;
}
#weatherButtons button:hover {
background: #555;
}
/* Common container for animations */
.weather-animation {
position: absolute;
width: 100%;
height: 100%;
}
/* ========================
WIND ANIMATION
======================== */
.wind .cloud {
position: absolute;
top: 30px;
left: -60px;
width: 80px;
height: 50px;
background: #f0f0f0;
border-radius: 50px;
opacity: 0.8;
animation: moveCloud 5s linear infinite;
}
/* Additional cloud for a fuller effect */
.wind .cloud:after {
content: '';
position: absolute;
top: -20px;
left: 20px;
width: 60px;
height: 60px;
background: #f0f0f0;
border-radius: 50%;
}
.wind .wind-line {
position: absolute;
width: 40px;
height: 2px;
background: #aaa;
top: 100px;
left: -50px;
opacity: 0.6;
transform: rotate(20deg);
animation: windFlow 3s linear infinite;
}
.wind .wind-line:nth-child(3) {
top: 120px;
animation-delay: 1s;
}
@keyframes moveCloud {
0% { left: -80px; }
100% { left: 220px; }
}
@keyframes windFlow {
0% { left: -50px; opacity: 0.6; }
100% { left: 210px; opacity: 0; }
}
/* ========================
RAIN ANIMATION
======================== */
.rain .raindrop {
position: absolute;
top: -20px;
width: 2px;
height: 10px;
background: #4da6ff;
border-radius: 50%;
opacity: 0.7;
animation: fall 1s linear infinite;
}
/* Create several raindrops at different positions and delays */
.rain .raindrop:nth-child(1) { left: 20%; animation-delay: 0s; }
.rain .raindrop:nth-child(2) { left: 40%; animation-delay: 0.2s; }
.rain .raindrop:nth-child(3) { left: 60%; animation-delay: 0.4s; }
.rain .raindrop:nth-child(4) { left: 80%; animation-delay: 0.6s; }
.rain .raindrop:nth-child(5) { left: 10%; animation-delay: 0.8s; }
@keyframes fall {
0% { top: -10px; opacity: 1; }
100% { top: 220px; opacity: 0; }
}
.rain .puddle {
position: absolute;
bottom: 0;
left: 25%;
width: 50%;
height: 10px;
background: #3366cc;
border-radius: 50%;
opacity: 0.5;
}
/* ========================
SUN ANIMATION
======================== */
.sun .sun-core {
position: absolute;
top: 50%;
left: 50%;
width: 60px;
height: 60px;
margin-top: -30px;
margin-left: -30px;
background: #ffcc00;
border-radius: 50%;
z-index: 2;
box-shadow: 0 0 20px 5px rgba(255, 204, 0, 0.6);
}
.sun .sun-ray {
position: absolute;
top: 50%;
left: 50%;
width: 6px;
height: 30px;
background: #ffcc00;
transform-origin: bottom center;
border-radius: 3px;
animation: rotateRay 6s linear infinite;
}
/* Create several rays rotated at different angles */
.sun .sun-ray:nth-child(2) { transform: translate(-50%, -100%) rotate(0deg); }
.sun .sun-ray:nth-child(3) { transform: translate(-50%, -100%) rotate(45deg); }
.sun .sun-ray:nth-child(4) { transform: translate(-50%, -100%) rotate(90deg); }
.sun .sun-ray:nth-child(5) { transform: translate(-50%, -100%) rotate(135deg); }
.sun .sun-ray:nth-child(6) { transform: translate(-50%, -100%) rotate(180deg); }
.sun .sun-ray:nth-child(7) { transform: translate(-50%, -100%) rotate(225deg); }
.sun .sun-ray:nth-child(8) { transform: translate(-50%, -100%) rotate(270deg); }
.sun .sun-ray:nth-child(9) { transform: translate(-50%, -100%) rotate(315deg); }
@keyframes rotateRay {
from { transform: translate(-50%, -100%) rotate(0deg); }
to { transform: translate(-50%, -100%) rotate(360deg); }
}
/* Bright background effect for sun */
.sun {
background: radial-gradient(circle, #ffee88 20%, #1d1d1d 80%);
}
/* ========================
SNOW ANIMATION
======================== */
.snow .snowflake {
position: absolute;
top: -10px;
font-size: 16px;
color: #fff;
opacity: 0.8;
animation: snowFall 3s linear infinite;
}
/* Several snowflakes with different positions and delays */
.snow .snowflake:nth-child(1) { left: 20%; animation-delay: 0s; }
.snow .snowflake:nth-child(2) { left: 40%; animation-delay: 0.5s; }
.snow .snowflake:nth-child(3) { left: 60%; animation-delay: 1s; }
.snow .snowflake:nth-child(4) { left: 80%; animation-delay: 1.5s; }
.snow .snowflake:nth-child(5) { left: 30%; animation-delay: 0.3s; }
@keyframes snowFall {
0% { top: -10px; opacity: 0.8; }
100% { top: 220px; opacity: 0; }
}
.snow .accumulated {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 15px;
background: rgba(255, 255, 255, 0.9);
}
</style>
</head>
<body>
<h1>Animated Weather Cards</h1>
<!-- Dynamic Weather Card With Controls -->
<div id="dynamicSection">
<h2>Dynamic Weather Card (click buttons below)</h2>
<div id="dynamicCard" class="weather-card"></div>
<div id="weatherButtons">
<button onclick="changeWeather('wind')">Wind</button>
<button onclick="changeWeather('rain')">Rain</button>
<button onclick="changeWeather('sun')">Sun</button>
<button onclick="changeWeather('snow')">Snow</button>
</div>
</div>
<hr style="border-color: #444; margin: 40px 0;"/>
<!-- Preset Weather Cards Shown Side by Side -->
<h2>Preset Weather Cards</h2>
<div class="cards-container">
<!-- Wind Card -->
<div class="weather-card wind">
<div class="weather-animation">
<div class="cloud"></div>
<div class="wind-line"></div>
</div>
<div style="position:absolute;bottom:5px;right:5px; font-size:14px;">Wind</div>
</div>
<!-- Rain Card -->
<div class="weather-card rain">
<div class="weather-animation">
<!-- Create several raindrops -->
<div class="raindrop"></div>
<div class="raindrop"></div>
<div class="raindrop"></div>
<div class="raindrop"></div>
<div class="raindrop"></div>
<div class="puddle"></div>
</div>
<div style="position:absolute;bottom:5px;right:5px; font-size:14px;">Rain</div>
</div>
<!-- Sun Card -->
<div class="weather-card sun">
<div class="weather-animation">
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-ray"></div>
<div class="sun-core"></div>
</div>
<div style="position:absolute;bottom:5px;right:5px; font-size:14px;">Sun</div>
</div>
<!-- Snow Card -->
<div class="weather-card snow">
<div class="weather-animation">
<div class="snowflake">❆</div>
<div class="snowflake">❆</div>
<div class="snowflake">❆</div>
<div class="snowflake">❆</div>
<div class="snowflake">❆</div>
<div class="accumulated"></div>
</div>
<div style="position:absolute;bottom:5px;right:5px; font-size:14px;">Snow</div>
</div>
</div>
<script>
// Render the specified weather animation into the dynamic card.
const dynamicCard = document.getElementById('dynamicCard');
function changeWeather(condition) {
// Clear any existing content and reset classes.
dynamicCard.innerHTML = '';
dynamicCard.className = 'weather-card ' + condition;
// Create a container for the animation.
const animContainer = document.createElement('div');
animContainer.className = 'weather-animation';
if (condition === 'wind') {
// Wind: add a moving cloud and a wind line.
const cloud = document.createElement('div');
cloud.className = 'cloud';
animContainer.appendChild(cloud);
const windLine = document.createElement('div');
windLine.className = 'wind-line';
animContainer.appendChild(windLine);
}
else if (condition === 'rain') {
// Rain: add several raindrops and a puddle.
for (let i = 0; i < 5; i++) {
const drop = document.createElement('div');
drop.className = 'raindrop';
animContainer.appendChild(drop);
}
const puddle = document.createElement('div');
puddle.className = 'puddle';
animContainer.appendChild(puddle);
}
else if (condition === 'sun') {
// Sun: add several rotating rays and the sun core.
for (let i = 0; i < 8; i++) {
const ray = document.createElement('div');
ray.className = 'sun-ray';
animContainer.appendChild(ray);
}
const core = document.createElement('div');
core.className = 'sun-core';
animContainer.appendChild(core);
}
else if (condition === 'snow') {
// Snow: add some snowflakes and an "accumulated" layer.
for (let i = 0; i < 5; i++) {
const flake = document.createElement('div');
flake.className = 'snowflake';
flake.textContent = '❆';
animContainer.appendChild(flake);
}
const accumulated = document.createElement('div');
accumulated.className = 'accumulated';
animContainer.appendChild(accumulated);
}
dynamicCard.appendChild(animContainer);
}
// Initialize the dynamic card with "sun" condition.
changeWeather('sun');
</script>
</body>
</html>
Explanation
Structure and Styling:
The dark background is set on the <body> with a dark color.
Each weather card (both the dynamic one and the preset ones) is given the same base styling using the .weather-card class.
The .cards-container uses flexbox to arrange the four preset cards side by side.
Specific CSS animation keyframes (like @keyframes moveCloud, fall, rotateRay, and snowFall) are defined for each weather condition.
Weather Animations:
Wind: A cloud (with an extra pseudo-element for fullness) moves horizontally plus a “wind-line” animates across.
Rain: Multiple .raindrop elements fall (using the “fall” keyframe), and a puddle appears at the bottom.
Sun: The sun is composed of a core and multiple rays that rotate continuously.
Snow: Several snowflakes (using the ❆ character) fall and an “accumulated” layer appears at the bottom.
JavaScript Functionality:
The changeWeather function clears the current content and resets the dynamic card’s class so that the corresponding CSS rules are applied.
Depending on the weather condition passed, the appropriate HTML elements for that effect are created and appended.
The dynamic card initializes with the “sun” animation.
You can easily customize any animations or styling as needed. This single HTML file demonstrates both a dynamic example with buttons and a preset side‑by‑side view of weather cards for quick comparison. Enjoy!