An image gallery displays a collection of images in a visually appealing layout. This example demonstrates how to create a responsive image gallery using CSS Flexbox and transitions for hover effects.
.gallery {
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: center;
}
.gallery-item {
flex: 1 1 calc(33.333% - 20px);
box-sizing: border-box;
border-radius: 10px;
overflow: hidden;
position: relative;
cursor: pointer;
}
.gallery-item img {
width: 100%;
height: auto;
display: block;
transition: transform 0.3s ease;
}
.gallery-item:hover img {
transform: scale(1.05);
}
.gallery-item .caption {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
padding: 10px;
background: rgba(0, 0, 0, 0.6);
color: #fff;
text-align: center;
opacity: 0;
transition: opacity 0.3s ease;
}
.gallery-item:hover .caption {
opacity: 1;
}
@media (max-width: 768px) {
.gallery-item {
flex: 1 1 calc(50% - 20px);
}
}
@media (max-width: 480px) {
.gallery-item {
flex: 1 1 100%;
}
}