Coding task · HTML and CSS course · Module 5: Responsiveness

Responsive image gallery

Responsive images are like frescoes adapting to the temple wall! Key techniques: max-width: 100% (never exceed the container width, like a fresco that doesn't go beyond the wall), height: auto (maintain proportions like the Egyptian golden ratio), object-fit: cover/contain (how to crop the image - cover fills, contain shows everything). Width: 100% always stretches, max-width: 100% only stretches up to the natural size. Images are often the largest files - optimization is key!

Task

Create a responsive Egyptian gallery. HTML: <div class='gallery'> + 4 <img src='https://via.placeholder.com/800x600?text=Pyramid' alt='Pyramid'> + </div>. CSS: .gallery {display: flex; flex-wrap: wrap; gap: 20px; padding: 20px;} .gallery img {max-width: 100%; height: auto; border: 5px solid #FFD700; box-shadow: 0 4px 10px rgba(0,0,0,0.3);}. Then @media (min-width: 768px) {.gallery img {width: calc(50% - 10px);}}. Desktop @media (min-width: 1024px) {.gallery img {width: calc(25% - 15px); object-fit: cover; height: 200px;}}. Watch how the images adapt!