html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Animated Weather Cards</title>
<style>
/* Reset and base */
* {
box-sizing: border-box;
}
body {
margin: 0;
background: #121212;
color: #eee;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
padding: 20px;
}
h1 {
margin-bottom: 20px;
}
.buttons {
margin-bottom: 30px;
}
button {
background: #222;
border: 1.5px solid #555;
color: #eee;
padding: 10px 18px;
margin: 0 8px;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
transition: background 0.3s, border-color 0.3s;
}
button:hover, button.active {
background: #444;
border-color: #0af;
}
/* Container for cards */
.cards {
display: flex;
gap: 30px;
flex-wrap: wrap;
justify-content: center;
}
/* Card base */
.card {
background: #222;
border-radius: 20px;
width: 220px;
height: 280px;
box-shadow: 0 0 15px #0af5;
position: relative;
overflow: hidden;
user-select: none;
}
.card h2 {
text-align: center;
margin: 15px 0 10px;
font-weight: 700;
letter-spacing: 1.2px;
}
/* WIND CARD */
.wind {
background: linear-gradient(135deg, #1e2a38, #0a1a2a);
}
/* Clouds */
.wind .cloud {
position: absolute;
background: #ccc;
background: linear-gradient(135deg, #ddd, #bbb);
border-radius: 50% / 50%;
opacity: 0.85;
filter: drop-shadow(0 0 2px #aaa);
animation: windCloudMove linear infinite;
}
.wind .cloud1 {
width: 100px;
height: 60px;
top: 50px;
left: -120px;
animation-duration: 20s;
}
.wind .cloud1::before,
.wind .cloud1::after {
content: "";
position: absolute;
background: inherit;
border-radius: 50% / 50%;
}
.wind .cloud1::before {
width: 60px;
height: 60px;
top: -30px;
left: 15px;
}
.wind .cloud1::after {
width: 70px;
height: 70px;
top: -20px;
left: 50px;
}
.wind .cloud2 {
width: 80px;
height: 50px;
top: 120px;
left: -100px;
animation-duration: 15s;
animation-delay: 5s;
}
.wind .cloud2::before,
.wind .cloud2::after {
content: "";
position: absolute;
background: inherit;
border-radius: 50% / 50%;
}
.wind .cloud2::before {
width: 50px;
height: 50px;
top: -25px;
left: 10px;
}
.wind .cloud2::after {
width: 60px;
height: 60px;
top: -15px;
left: 40px;
}
/* Wind lines */
.wind .wind-lines {
position: absolute;
bottom: 40px;
left: 20px;
width: 180px;
height: 40px;
}
.wind .wind-line {
position: absolute;
border-radius: 20px;
background: #a0cfffcc;
opacity: 0.7;
animation: windLineMove linear infinite;
}
.wind .wind-line1 {
top: 5px;
left: -100px;
width: 120px;
height: 6px;
animation-duration: 6s;
}
.wind .wind-line2 {
top: 20px;
left: -150px;
width: 150px;
height: 4px;
animation-duration: 8s;
animation-delay: 2s;
}
.wind .wind-line3 {
top: 30px;
left: -130px;
width: 100px;
height: 5px;
animation-duration: 7s;
animation-delay: 1s;
}
@keyframes windCloudMove {
0% { transform: translateX(0); }
100% { transform: translateX(350px); }
}
@keyframes windLineMove {
0% { transform: translateX(0); opacity: 0.7; }
50% { opacity: 0.3; }
100% { transform: translateX(350px); opacity: 0.7; }
}
/* RAIN CARD */
.rain {
background: linear-gradient(180deg, #1a2a3a, #0a1a2a);
}
/* Clouds */
.rain .cloud {
position: absolute;
background: #a0a0a0;
background: linear-gradient(135deg, #bbb, #888);
border-radius: 50% / 50%;
opacity: 0.9;
filter: drop-shadow(0 0 3px #666);
}
.rain .cloud1 {
width: 120px;
height: 70px;
top: 40px;
left: 50px;
}
.rain .cloud1::before,
.rain .cloud1::after {
content: "";
position: absolute;
background: inherit;
border-radius: 50% / 50%;
}
.rain .cloud1::before {
width: 70px;
height: 70px;
top: -35px;
left: 20px;
}
.rain .cloud1::after {
width: 80px;
height: 80px;
top: -25px;
left: 60px;
}
/* Raindrops */
.rain .raindrop {
position: absolute;
width: 6px;
height: 18px;
background: linear-gradient(180deg, #4fc3f7, #0288d1);
border-radius: 50% / 60%;
opacity: 0.8;
filter: drop-shadow(0 0 3px #0af);
animation: raindropFall linear infinite;
}
.rain .raindrop1 { left: 60px; top: 110px; animation-duration: 1.2s; animation-delay: 0s; }
.rain .raindrop2 { left: 90px; top: 130px; animation-duration: 1.5s; animation-delay: 0.3s; }
.rain .raindrop3 { left: 120px; top: 115px; animation-duration: 1.3s; animation-delay: 0.6s; }
.rain .raindrop4 { left: 150px; top: 125px; animation-duration: 1.4s; animation-delay: 0.9s; }
.rain .raindrop5 { left: 180px; top: 110px; animation-duration: 1.1s; animation-delay: 1.1s; }
/* Puddle */
.rain .puddle {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
width: 140px;
height: 20px;
background: radial-gradient(ellipse at center, #0a4a7d 40%, transparent 80%);
border-radius: 50% / 100%;
opacity: 0.6;
animation: puddleRipple 3s ease-in-out infinite;
}
@keyframes raindropFall {
0% {
transform: translateY(0);
opacity: 0.8;
}
80% {
opacity: 0.8;
}
100% {
transform: translateY(90px);
opacity: 0;
}
}
@keyframes puddleRipple {
0%, 100% {
box-shadow: 0 0 10px 3px #0af8 inset;
opacity: 0.6;
}
50% {
box-shadow: 0 0 20px 6px #0afc inset;
opacity: 0.9;
}
}
/* SUN CARD */
.sun {
background: linear-gradient(135deg, #ffdd55, #ffaa00);
overflow: visible;
}
.sun .sun-core {
position: absolute;
top: 90px;
left: 50%;
transform: translateX(-50%);
width: 100px;
height: 100px;
background: radial-gradient(circle at center, #fff176, #fbc02d);
border-radius: 50%;
box-shadow:
0 0 30px 10px #fff176aa,
0 0 50px 20px #fbc02d88;
animation: sunGlow 3s ease-in-out infinite alternate;
z-index: 2;
}
/* Sun rays */
.sun .rays {
position: absolute;
top: 90px;
left: 50%;
transform: translateX(-50%);
width: 140px;
height: 140px;
pointer-events: none;
z-index: 1;
}
.sun .ray {
position: absolute;
width: 8px;
height: 40px;
background: linear-gradient(180deg, #fffacd, #fbc02d);
border-radius: 4px;
top: 10px;
left: 50%;
transform-origin: center bottom;
animation: rayPulse 3s ease-in-out infinite alternate;
}
.sun .ray:nth-child(1) { transform: translateX(-50%) rotate(0deg); animation-delay: 0s; }
.sun .ray:nth-child(2) { transform: translateX(-50%) rotate(30deg); animation-delay: 0.2s; }
.sun .ray:nth-child(3) { transform: translateX(-50%) rotate(60deg); animation-delay: 0.4s; }
.sun .ray:nth-child(4) { transform: translateX(-50%) rotate(90deg); animation-delay: 0.6s; }
.sun .ray:nth-child(5) { transform: translateX(-50%) rotate(120deg); animation-delay: 0.8s; }
.sun .ray:nth-child(6) { transform: translateX(-50%) rotate(150deg); animation-delay: 1s; }
.sun .ray:nth-child(7) { transform: translateX(-50%) rotate(180deg); animation-delay: 1.2s; }
.sun .ray:nth-child(8) { transform: translateX(-50%) rotate(210deg); animation-delay: 1.4s; }
.sun .ray:nth-child(9) { transform: translateX(-50%) rotate(240deg); animation-delay: 1.6s; }
.sun .ray:nth-child(10) { transform: translateX(-50%) rotate(270deg); animation-delay: 1.8s; }
.sun .ray:nth-child(11) { transform: translateX(-50%) rotate(300deg); animation-delay: 2s; }
.sun .ray:nth-child(12) { transform: translateX(-50%) rotate(330deg); animation-delay: 2.2s; }
@keyframes sunGlow {
0% { box-shadow: 0 0 30px 10px #fff176aa, 0 0 50px 20px #fbc02d88; }
100% { box-shadow: 0 0 40px 15px #fff176cc, 0 0 60px 25px #fbc02dbb; }
}
@keyframes rayPulse {
0% { opacity: 0.6; height: 40px; }
50% { opacity: 1; height: 50px; }
100% { opacity: 0.6; height: 40px; }
}
/* SNOW CARD */
.snow {
background: linear-gradient(180deg, #2a3a4a, #1a2a3a);
}
/* Snowflakes */
.snow .snowflake {
position: absolute;
color: #e0f7fa;
font-size: 18px;
user-select: none;
animation-name: snowFall, snowDrift;
animation-timing-function: linear, ease-in-out;
animation-iteration-count: infinite;
}
/* Different snowflakes with different delays and durations */
.snow .snowflake1 {
left: 30px;
top: -20px;
animation-duration: 8s, 4s;
animation-delay: 0s, 0s;
}
.snow .snowflake2 {
left: 80px;
top: -40px;
animation-duration: 10s, 5s;
animation-delay: 2s, 1s;
}
.snow .snowflake3 {
left: 130px;
top: -10px;
animation-duration: 7s, 3.5s;
animation-delay: 1s, 0.5s;
}
.snow .snowflake4 {
left: 170px;
top: -30px;
animation-duration: 9s, 4.5s;
animation-delay: 3s, 1.5s;
}
.snow .snowflake5 {
left: 200px;
top: -25px;
animation-duration: 11s, 6s;
animation-delay: 0.5s, 0.2s;
}
@keyframes snowFall {
0% { transform: translateY(0); opacity: 1; }
100% { transform: translateY(280px); opacity: 0.3; }
}
@keyframes snowDrift {
0%, 100% { transform: translateX(0); }
50% { transform: translateX(15px); }
}
/* Snow accumulation */
.snow .snow-accum {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 180px;
height: 30px;
background: linear-gradient(90deg, #e0f7facc, #b0e0facc);
border-radius: 50% / 100%;
box-shadow:
0 0 15px 5px #b0e0fa88 inset;
opacity: 0.8;
animation: snowAccumPulse 4s ease-in-out infinite;
}
@keyframes snowAccumPulse {
0%, 100% { opacity: 0.8; }
50% { opacity: 1; }
}
</style>
</head>
<body>
<h1>Animated Weather Cards</h1>
<div class="buttons" role="group" aria-label="Select weather condition">
<button id="btn-wind" class="active" aria-pressed="true">Wind</button>
<button id="btn-rain" aria-pressed="false">Rain</button>
<button id="btn-sun" aria-pressed="false">Sun</button>
<button id="btn-snow" aria-pressed="false">Snow</button>
</div>
<div class="cards">
<div class="card wind" aria-label="Wind weather card">
<h2>Wind</h2>
<div class="cloud cloud1"></div>
<div class="cloud cloud2"></div>
<div class="wind-lines">
<div class="wind-line wind-line1"></div>
<div class="wind-line wind-line2"></div>
<div class="wind-line wind-line3"></div>
</div>
</div>
<div class="card rain" aria-label="Rain weather card" hidden>
<h2>Rain</h2>
<div class="cloud cloud1"></div>
<div class="raindrop raindrop1"></div>
<div class="raindrop raindrop2"></div>
<div class="raindrop raindrop3"></div>
<div class="raindrop raindrop4"></div>
<div class="raindrop raindrop5"></div>
<div class="puddle"></div>
</div>
<div class="card sun" aria-label="Sun weather card" hidden>
<h2>Sun</h2>
<div class="sun-core"></div>
<div class="rays">
<div class="ray"></div>
<div class="ray"></div>
<div class="ray"></div>
<div class="ray"></div>
<div class="ray"></div>
<div class="ray"></div>
<div class="ray"></div>
<div class="ray"></div>
<div class="ray"></div>
<div class="ray"></div>
<div class="ray"></div>
<div class="ray"></div>
</div>
</div>
<div class="card snow" aria-label="Snow weather card" hidden>
<h2>Snow</h2>
<div class="snowflake snowflake1">❄</div>
<div class="snowflake snowflake2">❄</div>
<div class="snowflake snowflake3">❄</div>
<div class="snowflake snowflake4">❄</div>
<div class="snowflake snowflake5">❄</div>
<div class="snow-accum"></div>
</div>
</div>
<script>
const buttons = document.querySelectorAll('.buttons button');
const cards = document.querySelectorAll('.cards .card');
function setActiveWeather(weather) {
cards.forEach(card => {
if (card.classList.contains(weather)) {
card.hidden = false;
} else {
card.hidden = true;
}
});
buttons.forEach(btn => {
if (btn.id === 'btn-' + weather) {
btn.classList.add('active');
btn.setAttribute('aria-pressed', 'true');
} else {
btn.classList.remove('active');
btn.setAttribute('aria-pressed', 'false');
}
});
}
buttons.forEach(btn => {
btn.addEventListener('click', () => {
const weather = btn.id.replace('btn-', '');
setActiveWeather(weather);
});
});
// Initialize with wind active
setActiveWeather('wind');
</script>
</body>
</html>