.btn { padding: 20px 40px; border: 3px solid #fff; border-radius: 15px; cursor: pointer; font-size: 1.5em; position: relative; overflow: hidden; transition: all 0.3s ease; } .btn-explode { background: #ff4500; /* Default color, override with inline styles for others */ color: #fff; } .btn-explode.clicked::after { content: "BOOM!"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 2em; color: #ffff00; animation: explodeText 0.5s forwards; } .btn-explode.clicked { animation: explode 0.5s forwards; } @keyframes explode { 0% { transform: scale(1); } 50% { transform: scale(2); background: #ffff00; } 100% { transform: scale(0); opacity: 0; } } @keyframes explodeText { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0); } 50% { opacity: 1; transform: translate(-50%, -50%) scale(1.5); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(2); } }
// The onclick is handled in the HTML with classList.add('clicked') - no extra JS needed!
.btn-vanish { background: #00ff99; color: #000; } .btn-vanish.clicked { animation: vanish 0.8s forwards; } .btn-vanish.clicked::before { content: "POOF!"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #ff00ff; font-size: 2em; animation: poofText 0.8s forwards; } .btn-grow-glow { background: #800080; color: #fff; } .btn-grow-glow:hover { transform: scale(1.5); box-shadow: 0 0 20px #ff00ff, 0 0 40px #00ffff, 0 0 60px #ffff00; animation: glowPulse 1s infinite alternate; } @keyframes vanish { 0% { transform: scale(1) rotate(0); } 50% { transform: scale(0.5) rotate(180deg); background: #ff00ff; } 100% { transform: scale(0) rotate(360deg); opacity: 0; } } @keyframes poofText { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0); } 50% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(0); } } @keyframes glowPulse { 0% { box-shadow: 0 0 20px #ff00ff; } 100% { box-shadow: 0 0 60px #00ffff; } }
// The onclick for vanish is in the HTML - no extra JS needed here either!