CSS Image Gallery
An image gallery is a great way to showcase multiple images in a visually appealing format. CSS can be used to create a gallery that adjusts to different screen sizes, providing a responsive layout.
Basic Image Gallery
Below is a simple example of a grid-based image gallery:
/* Basic Image Gallery */
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 10px;
}
.gallery img {
width: 100%;
height: auto;
border-radius: 8px;
transition: transform 0.3s ease;
}
.gallery img:hover {
transform: scale(1.05);
}
Responsive Image Gallery
For a responsive design that adjusts to various screen sizes, you can use media queries to modify the grid layout:
/* Responsive Image Gallery */
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 10px;
}
.gallery img {
width: 100%;
height: auto;
border-radius: 8px;
transition: transform 0.3s ease;
}
.gallery img:hover {
transform: scale(1.05);
}
/* Media Queries for Smaller Screens */
@media (max-width: 768px) {
.gallery {
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}
}