DEV Community

Cover image for Creating an Interactive Image Gallery with HTML and CSS

Creating an Interactive Image Gallery with HTML and CSS

Alvaro Montoro on November 13, 2023

The other day, while navigating online looking for inspiration, I found a photo gallery design by kevin on Dribbble, so I decided to create a minim...
Collapse
 
francescovetere profile image
Francesco Vetere

This is awesome! 🤩
Particularly loved the clever use of :has(), it was really perfect in this situation and I cannot think of another CSS-only solution to obtain the same result without using it. Amazing!

Collapse
 
lexiebkm profile image
Alexander B.K.

Unfortunately, Firefox does not provide full-support to the :has pseudo-class. See
issue on Firefox

Collapse
 
auroratide profile image
Timothy Foster

What's great about this gallery solution, though, is that even without has it still works. I may not get the fancy greyscaling effect in Firefox, but it's nevertheless laid out nicely and still makes it obvious what image I'm highlighting.

A great example of progressive enhancement in action ( :

Thread Thread
 
francescovetere profile image
Francesco Vetere

Good point! 💪

Collapse
 
francescovetere profile image
Francesco Vetere

It seems that from version 121, Firefox will finally support it! 😉 caniuse.com/css-has

Collapse
 
tatu profile image
Vkad

Hey, love the idea. Was just wondering if I wanted to make each image a link how would go about and do this, because I tried this in VS code and it keeps overlapping the images.
Thank you in advance.

Collapse
 
alvaromontoro profile image
Alvaro Montoro

That happens because the CSS needs to be updated (just slightly). Here's a demo with links:

Collapse
 
tatu profile image
Vkad

Thank you so much!! This really helped a lot.

Thread Thread
 
tatu profile image
Vkad

I do have another inquiry if its not too much trouble. I was wondering what would I have to change in the CSS to make the hovered image appear larger but not overlap with the other images(So they would still be clickable).

Thread Thread
 
alvaromontoro profile image
Alvaro Montoro

I don't fully understand the request (they are still clickable.) Maybe on hover you could remove the new clip-path and add a scale() instead.

Thread Thread
 
tatu profile image
Vkad

Sorry if I was too confusing. I was just wondering how I could make the image bigger when hovering over it withour changing the initial size.

Collapse
 
oskargrosser profile image
Oskar Grosser

Nice effect! You should try out different transformations for revealing the full image, like rotating from rhombus to square, transforming from rhombus to circle to square, "unfolding" from rhombus to square, etc.

Speaking of the animation, I noticed that the transformation isn't symmetric: The top corners of the square come from the top corner of the rhombus (which looks fine), but the bottom-left and bottom-right corner of the square come from the bottom and right corner of the rhombus, respectively. This makes the transformation look off.

Collapse
 
ackvf profile image
Vítězslav Ackermann Ferko

Very nice effect.

Collapse
 
anitaolsen profile image
Anita Olsen*°•.¸☆

This is totally awesome, I LOVE IT! ✨

Collapse
 
russellbateman profile image
Russell Bateman

Way cool, friend!

Collapse
 
arthors01 profile image
arthorS01

Thank you so much for this!

Collapse
 
abrarali14 profile image
Abrar Ali

*Please make another thing *
❤❤❤❤❤

Collapse
 
genlyai_ profile image
Walter Santos

Many good tips! Thank you!