HTML Exercises

Responsive Photo Gallery

Create a responsive photo gallery using internal CSS. The gallery should adjust to various screen sizes, with images resizing and rearranging as needed. Implement hover effects for each image.

    HTML (index.html)
    <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Responsive Photo Gallery</title>
            <style>
                /* Reset some default styles */
                body {
                    margin: 0;
                    font-family: Arial, sans-serif;
                    background-color: #f4f4f4;
                }
        
                .gallery {
                    display: grid;
                    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
                    gap: 10px;
                    padding: 10px;
                }
        
                .gallery-item {
                    position: relative;
                    overflow: hidden;
                    border-radius: 8px;
                    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
                }
        
                .gallery-item img {
                    width: 100%;
                    height: auto;
                    display: block;
                    transition: transform 0.3s ease;
                }
        
                .gallery-item:hover img {
                    transform: scale(1.1);
                }
        
                @media (max-width: 600px) {
                    .gallery {
                        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
                    }
                }
            </style>
        </head>
        <body>
            <div class="gallery">
                <div class="gallery-item">
                    <img src="https://via.placeholder.com/600x400" alt="Sample Image 1">
                </div>
                <div class="gallery-item">
                    <img src="https://via.placeholder.com/600x600" alt="Sample Image 2">
                </div>
                <div class="gallery-item">
                    <img src="https://via.placeholder.com/400x400" alt="Sample Image 3">
                </div>
                <div class="gallery-item">
                    <img src="https://via.placeholder.com/800x600" alt="Sample Image 4">
                </div>
                <div class="gallery-item">
                    <img src="https://via.placeholder.com/600x800" alt="Sample Image 5">
                </div>
            </div>
        </body>
        </html>
        
  1. Save and open index.html in your browser to view your website.

Feel free to customize the content and structure as you like.