Toggle navigation
☰
HTML
CSS
Scripting
Database
<!doctype html> <title>Example</title> <style> body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; font-family: sans-serif; background-color: #f0f0f0; } .card { position: relative; width: 300px; height: 200px; border-radius: 8px; overflow: hidden; box-shadow: 0 4px 8px rgba(0,0,0,0.1); } .card img { width: 100%; height: 100%; object-fit: cover; display: block; } /* The caption overlay starting state */ .caption { position: absolute; bottom: 0; left: 0; width: 100%; background: rgba(0, 0, 0, 0.7); color: white; padding: 15px; box-sizing: border-box; /* Move caption entirely out of frame downwards */ transform: translateY(100%); transition: transform 0.3s ease-in-out; } .caption h3 { margin: 0 0 5px 0; font-size: 1.2rem; } .caption p { margin: 0; font-size: 0.9rem; color: #ccc; } /* On hover, slide the caption back into view */ .card:hover .caption, .card:focus-within .caption { transform: translateY(0); } @media (prefers-reduced-motion: reduce) { .caption { transition: none; /* Instant snap */ } } </style> <div class="card" tabindex="0"> <img src="/pix/samples/30m.jpg" alt="Beach photo demonstrating zoom effect" /> <div class="caption"> <h3>Ocean Voyage</h3> <p>Explore unseen territories.</p> </div> </div>