Grok 4.1 Fast· xai
Frontier Reasoning Traces
Create a CSS-only image gallery with hover effects and lightbox functionality.
- User
Create a CSS-only image gallery with hover effects and lightbox functionality.
- Assistant
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS-Only Image Gallery with Hover Effects & Lightbox</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f4f4f9; padding: 20px; line-height: 1.6; transition: overflow 0.3s ease; } body:has(.lightbox:target) { overflow: hidden; } h1 { text-align: center; margin-bottom: 40px; color: #333; font-size: 2.5em; font-weight: 300; } .gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; max-width: 1400px; margin: 0 auto; } .thumb { position: relative; display: block; height: 220px; border-radius: 16px; overflow: hidden; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1); transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94); text-decoration: none; } .thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s ease; } .thumb:hover { transform: translateY(-12px) scale(1.02); box-shadow: 0 20px 48px rgba(0, 0, 0, 0.2); } .thumb:hover img { transform: scale(1.1); } .overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: linear-gradient(135deg, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.3)); opacity: 0; transition: opacity 0.4s ease; display: flex; align-items: center; justify-content: center; color: white; font-size: 1.4em; font-weight: 500; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5); } .thumb:hover .overlay { opacity: 1; } /* Lightbox */ .lightbox { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0, 0, 0, 0.95); z-index: 1000; align-items: center; justify-content: center; padding: 40px; opacity: 0; transition: opacity 0.3s ease; } .lightbox:target { display: flex; opacity: 1; } .lightbox img { max-width: 95%; max-height: 95%; object-fit: contain; border-radius: 8px; box-shadow: 0 0 60px rgba(255, 255, 255, 0.1); } .close { position: absolute; top: 32px; right: 40px; color: #fff; font-size: 3em; font-weight: bold; text-decoration: none; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5); transition: color 0.3s ease, transform 0.3s ease; z-index: 1001; line-height: 1; width: 50px; height: 50px; display: flex; align-items: center; justify-content: center; border-radius: 50%; } .close:hover { color: #ff6b6b; transform: scale(1.1); background: rgba(255, 255, 255, 0.1); } /* Responsive */ @media (max-width: 768px) { body { padding: 10px; } h1 { font-size: 2em; margin-bottom: 30px; } .gallery { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; } .thumb { height: 200px; } .lightbox { padding: 20px; } .close { top: 20px; right: 24px; font-size: 2.5em; } } @media (max-width: 480px) { .gallery { grid-template-columns: 1fr; } } </style> </head> <body> <h1>CSS-Only Image Gallery</h1> <div class="gallery"> <a href="#img1" class="thumb"> <img src="https://picsum.photos/seed/1/400/300" alt="Landscape 1" loading="lazy"> <div class="overlay">View Image</div> </a> <a href="#img2" class="thumb"> <img src="https://picsum.photos/seed/2/400/300" alt="Landscape 2" loading="lazy"> <div class="overlay">View Image</div> </a> <a href="#img3" class="thumb"> <img src="https://picsum.photos/seed/3/400/300" alt="Landscape 3" loading="lazy"> <div class="overlay">View Image</div> </a> <a href="#img4" class="thumb"> <img src="https://picsum.photos/seed/4/400/300" alt="Landscape 4" loading="lazy"> <div class="overlay">View Image</div> </a> <a href="#img5" class="thumb"> <img src="https://picsum.photos/seed/5/400/300" alt="Landscape 5" loading="lazy"> <div class="overlay">View Image</div> </a> <a href="#img6" class="thumb"> <img src="https://picsum.photos/seed/6/400/300" alt="Landscape 6" loading="lazy"> <div class="overlay">View Image</div> </a> </div> <!-- Lightbox Modals --> <div id="img1" class="lightbox"> <a href="#" class="close" title="Close">×</a> <img src="https://picsum.photos/seed/1/1400/900" alt="Landscape 1" loading="lazy"> </div> <div id="img2" class="lightbox"> <a href="#" class="close" title="Close">×</a> <img src="https://picsum.photos/seed/2/1400/900" alt="Landscape 2" loading="lazy"> </div> <div id="img3" class="lightbox"> <a href="#" class="close" title="Close">×</a> <img src="https://picsum.photos/seed/3/1400/900" alt="Landscape 3" loading="lazy"> </div> <div id="img4" class="lightbox"> <a href="#" class="close" title="Close">×</a> <img src="https://picsum.photos/seed/4/1400/900" alt="Landscape 4" loading="lazy"> </div> <div id="img5" class="lightbox"> <a href="#" class="close" title="Close">×</a> <img src="https://picsum.photos/seed/5/1400/900" alt="Landscape 5" loading="lazy"> </div> <div id="img6" class="lightbox"> <a href="#" class="close" title="Close">×</a> <img src="https://picsum.photos/seed/6/1400/900" alt="Landscape 6" loading="lazy"> </div> </body> </html>Features:
- Pure CSS: No JavaScript required.
- Responsive Grid: Adapts to screen size (desktop, tablet, mobile).
- Hover Effects: Thumbnails lift, scale, and reveal a gradient overlay with "View Image" text.
- Lightbox: Click a thumbnail to open full-screen modal. Uses
:targetpseudo-class. - Close Functionality: Click the × button (links to
#to clear target). Also supports browser back/forward. - Scroll Lock: Body scroll is disabled when lightbox is open (using
:has()selector – modern browsers). - Smooth Animations: Cubic-bezier transitions for polished feel.
- Performance: Lazy loading on images.
- Accessibility: Alt texts, titles, semantic structure.
Copy-paste into an HTML file and open in a browser. Works best in modern browsers (Chrome 105+, Firefox 121+, Safari 15.4+ for
:has()). For older browsers, scroll lock may not work, but lightbox functions perfectly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.