-
Hajipur, Bihar, 844101
A CSS Image Gallery is a visual arrangement of multiple images in a grid or flexible layout on a web page. It allows users to view, interact with, and explore images in an organized and aesthetic way using only HTML and CSS (no JavaScript required for basic functionality).
CSS image galleries can be created using:
Flexbox – 1D layout with row or column wrapping
Grid – 2D layout with rows and columns
Float – Older method (less flexible)
Media Queries – For responsive galleries
<div class="gallery">
<img src="img1.jpg" alt="">
<img src="img2.jpg" alt="">
<img src="img3.jpg" alt="">
<img src="img4.jpg" alt="">
</div>
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 15px;
padding: 20px;
}
.gallery img {
width: 100%;
height: auto;
display: block;
border-radius: 8px;
}
.gallery {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.gallery img {
width: calc(33.33% - 10px);
}
@media screen and (max-width: 768px) {
.gallery img {
width: 48%;
}
}
@media screen and (max-width: 480px) {
.gallery img {
width: 100%;
}
}
✅ Write CSS for the following:
Q1. Create a responsive 3-column image gallery using Grid.
Q2. Add spacing between gallery items using gap
.
Q3. Add rounded corners to gallery images.
Q4. Create a hover effect to scale the image.
Q5. Display image captions over the images.
Q6. Make a flex-based image gallery.
Q7. Set all images to the same height using object-fit
.
Q8. Use media queries to change layout on mobile.
Q9. Create a gallery with a border around each image.
Q10. Add a shadow effect to gallery images.
Q1: Which CSS property creates a grid layout?
Q2: How do you make gallery images flexible in width?
Q3: Which unit makes galleries responsive automatically?
Q4: What does flex-wrap: wrap; do?
Q5: How do you apply spacing in CSS Grid?
Q6: Which property is used to round image corners?
Q7: Which value helps maintain image proportion?
Q8: Which media query targets screens less than 480px wide?
Q9: What does object-fit: cover; do to images in a gallery?
Q10: Which layout system allows both rows and columns?