Here's a complete HTML file with animated weather cards:
<!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>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #1a1a1a;
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
}
.container {
display: flex;
gap: 30px;
flex-wrap: wrap;
justify-content: center;
}
.weather-card {
width: 250px;
height: 350px;
background: #2a2a2a;
border-radius: 20px;
overflow: hidden;
position: relative;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.weather-info {
position: absolute;
bottom: 20px;
left: 20px;
color: white;
z-index: 10;
}
.weather-info h2 {
font-size: 24px;
margin-bottom: 5px;
}
.weather-info p {
font-size: 14px;
opacity: 0.8;
}
/* Wind Animation */
.wind-card {
background: linear-gradient(to bottom, #4a5568, #2d3748);
}
.wind-lines {
position: absolute;
width: 100%;
height: 100%;
}
.wind-line {
position: absolute;
height: 2px;
background: rgba(255, 255, 255, 0.3);
animation: windMove 3s linear infinite;
}
.wind-line:nth-child(1) { top: 20%; width: 60%; animation-delay: 0s; }
.wind-line:nth-child(2) { top: 40%; width: 80%; animation-delay: 0.5s; }
.wind-line:nth-child(3) { top: 60%; width: 70%; animation-delay: 1s; }
.wind-line:nth-child(4) { top: 80%; width: 90%; animation-delay: 1.5s; }
@keyframes windMove {
0% { transform: translateX(-100%); }
100% { transform: translateX(200%); }
}
.cloud {
position: absolute;
background: rgba(255, 255, 255, 0.4);
border-radius: 100px;
opacity: 0.8;
}
.cloud::before,
.cloud::after {
content: '';
position: absolute;
background: rgba(255, 255, 255, 0.4);
border-radius: 100px;
}
.cloud1 {
width: 100px;
height: 40px;
top: 20%;
animation: cloudMove 20s linear infinite;
}
.cloud1::before {
width: 50px;
height: 50px;
top: -25px;
left: 10px;
}
.cloud1::after {
width: 60px;
height: 40px;
top: -15px;
right: 10px;
}
@keyframes cloudMove {
0% { transform: translateX(-150px); }
100% { transform: translateX(400px); }
}
/* Rain Animation */
.rain-card {
background: linear-gradient(to bottom, #1e3a5f, #0f2027);
}
.rain-drop {
position: absolute;
width: 2px;
height: 20px;
background: linear-gradient(to bottom, transparent, #4fc3f7);
animation: rainFall linear infinite;
}
@keyframes rainFall {
0% { transform: translateY(-100px); }
100% { transform: translateY(400px); }
}
/* Sun Animation */
.sun-card {
background: linear-gradient(to bottom, #87CEEB, #FFD700);
}
.sun {
position: absolute;
width: 100px;
height: 100px;
background: #FFD700;
border-radius: 50%;
top: 30px;
right: 30px;
box-shadow: 0 0 50px #FFD700;
animation: sunPulse 4s ease-in-out infinite;
}
.sun-ray {
position: absolute;
top: 50%;
left: 50%;
width: 150px;
height: 3px;
background: linear-gradient(to right, transparent, #FFD700, transparent);
transform-origin: left center;
animation: sunRotate 10s linear infinite;
}
.sun-ray:nth-child(1) { transform: rotate(0deg); }
.sun-ray:nth-child(2) { transform: rotate(45deg); }
.sun-ray:nth-child(3) { transform: rotate(90deg); }
.sun-ray:nth-child(4) { transform: rotate(135deg); }
.sun-ray:nth-child(5) { transform: rotate(180deg); }
.sun-ray:nth-child(6) { transform: rotate(225deg); }
.sun-ray:nth-child(7) { transform: rotate(270deg); }
.sun-ray:nth-child(8) { transform: rotate(315deg); }
@keyframes sunPulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.1); }
}
@keyframes sunRotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Snow Animation */
.snow-card {
background: linear-gradient(to bottom, #4a5568, #718096);
}
.snowflake {
position: absolute;
color: white;
font-size: 1em;
animation: snowFall linear infinite;
}
@keyframes snowFall {
0% {
transform: translateY(-100px) rotate(0deg);
opacity: 1;
}
100% {
transform: translateY(400px) rotate(360deg);
opacity: 0.3;
}
}
.snow-ground {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
background: linear-gradient(to top, white, transparent);
opacity: 0.6;
}
/* Button Styles */
.controls {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 10px;
z-index: 100;
}
button {
padding: 10px 20px;
background: #4a5568;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background 0.3s;
}
button:hover {
background: #2d3748;
}
button.active {
background: #3182ce;
}
</style>
</head>
<body>
<div class="container">
<!-- Wind Card -->
<div class="weather-card wind-card" id="windCard">
<div class="wind-lines">
<div class="wind-line"></div>
<div class="wind-line"></div>
<div class="wind-line"></div>
<div class="wind-line"></div>
</div>
<div class="cloud cloud1"></div>
<div class="weather-info">
<h2>Windy</h2>
<p>25 mph winds</p>
</div>
</div>
<!-- Rain Card -->
<div class="weather-card rain-card" id="rainCard">
<div class="weather-info">
<h2>Rainy</h2>
<p>Heavy showers</p>
</div>
</div>
<!-- Sun Card -->
<div class="weather-card sun-card" id="sunCard">
<div class="sun">
<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>
<div class="weather-info">
<h2>Sunny</h2>
<p>Clear skies</p>
</div>
</div>
<!-- Snow Card -->
<div class="weather-card snow-card" id="snowCard">
<div class="snow-ground"></div>
<div class="weather-info">
<h2>Snowy</h2>
<p>Light snowfall</p>
</div>
</div>
</div>
<script>
// Create rain drops
function createRainDrops() {
const rainCard = document.getElementById('rainCard');
for (let i = 0; i < 50; i++) {
const drop = document.createElement('div');
drop.className = 'rain-drop';
drop.style.left = Math.random() * 100 + '%';
drop.style.animationDuration = (Math.random() * 1 + 0.5) + 's';
drop.style.animationDelay = Math.random() * 2 + 's';
rainCard.appendChild(drop);
}
}
// Create snowflakes
function createSnowflakes() {
const snowCard = document.getElementById('snowCard');
const snowflakeSymbols = ['❄', '❅', '❆'];
for (let i = 0; i < 30; i++) {
const snowflake = document.createElement('div');
snowflake.className = 'snowflake';
snowflake.innerHTML = snowflakeSymbols[Math.floor(Math.random() * snowflakeSymbols.length)];
snowflake.style.left = Math.random() * 100 + '%';
snowflake.style.animationDuration = (Math.random() * 3 + 2) + 's';
snowflake.style.animationDelay = Math.random() * 3 + 's';
snowflake.style.fontSize = (Math.random() * 10 + 10) + 'px';
snowCard.appendChild(snowflake);
}
}
// Initialize animations
createRainDrops();
createSnowflakes();
// Optional: Add interactive controls
function addControls() {
const controls = document.createElement('div');
controls.className = 'controls';
const weatherTypes = ['Wind', 'Rain', 'Sun', 'Snow'];
weatherTypes.forEach(type => {
const button = document.createElement('button');
button.textContent = type;
button.onclick = () => {
document.querySelectorAll('.weather-card').forEach(card => {
card.style.display = 'none';
});
document.getElementById(type.toLowerCase() + 'Card').style.display = 'block';
document.querySelectorAll('button').forEach(btn => btn.classList.remove('active'));
button.classList.add('active');
};
controls.appendChild(button);
});
const showAllButton = document.createElement('button');
showAllButton.textContent = 'Show All';
showAllButton.onclick = () => {
document.querySelectorAll('.weather-card').forEach(card => {
card.style.display = 'block';
});
document.querySelectorAll('button').forEach(btn => btn.classList.remove('active'));
showAllButton.classList.add('active');
};
showAllButton.classList.add('active');
controls.appendChild(showAllButton);
document.body.appendChild(controls);
}
// Uncomment the line below to add interactive controls
// addControls();
</script>
</body>
</html>
This HTML file creates four animated weather cards displayed side by side:
- Wind Card: Features moving horizontal wind lines and a floating cloud animation
- Rain Card: Shows falling raindrops with varying speeds and positions
- Sun Card: Displays a pulsing sun with rotating rays
- Snow Card: Has falling snowflakes with rotation and accumulated snow at the bottom
Each card has a dark-themed background with distinct color gradients. The animations are continuous and use CSS keyframes for smooth performance. If you want to add interactive controls to switch between weather conditions, simply uncomment the addControls() line at the bottom of the JavaScript section.