<div class="gallery">
<figure>
<img src="https://images.unsplash.com/photo-1556150443-7254ffb98961?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI2MTM3NDk&ixlib=rb-4.0.3&q=80&w=400" alt="A group of penguins walking in a single-file line on a rocky shore. " title="Penguin photo by Yomex Owo for Unsplash">
<figcaption>Penguins on parade</figcaption>
</figure>
<figure>
<img src="https://images.unsplash.com/photo-1579190519828-316f39307e61?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI2MTM3NDk&ixlib=rb-4.0.3&q=80&w=400" alt="A group of penguins walking onshore from a body of water. " title="Penguin photo by Rebekah Blocker for Unsplash">
</figure>
<figure>
<img src="https://images.unsplash.com/photo-1546200043-0461108b05b0?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI2MTM4NTY&ixlib=rb-4.0.3&q=80&w=400" alt="Two puffins sitting in grass in front of water, facing each other. " title="Puffin photo by Jolan Wathelet for Unsplash">
<figcaption>A pair of puffins</figcaption>
</figure>
<figure>
<img src="https://images.unsplash.com/photo-1471277492184-078d3fe6b419?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI2MTM5MDc&ixlib=rb-4.0.3&q=80&w=400" alt="A puffin standing on a rocky ledge over water. " title="Puffin photo by Jonatan Pie for Unsplash">
</figure>
</div>
@import url("https://fonts.googleapis.com/css2?family=Lato&display=swap");
body {
font-family: "Lato", sans-serif;
}
.gallery {
display: grid;
grid-gap: 1px;
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.gallery img {
width: 100%;
border-radius: 10px;
height: 15rem;
}
figure {
height: 15rem;
border-radius: 10px;
}
figure:hover {
transform: scale(1.1);
box-shadow: 0px 10px 20px 2px rgba(0, 0, 0, 0.25);
animation: gradient 5s ease infinite;
}
figcaption {
padding: 0.2em;
text-align: center;
}
@keyframes gradient {
0% {
background-position: 0% 50%;
color: black;
}
50% {
background-position: 100% 50%;
color: black;
}
100% {
background-position: 0% 50%;
color: black;
}
}
@supports (selector(:has(*))) {
figure:has(figcaption) {
border-radius: 10px;
box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.5);
background: linear-gradient(to right, #0e6655, #d0ece7);
color: white;
height: 18rem;
background-size: 400% 400%;
}
}
if (!CSS.supports("selector(:where())")) {
const galleryFigures = document.querySelectorAll("figure");
// loop over each HTML figure element to find if figcaption is present
for (let figure of galleryFigures) {
console.log(figure.children.length);
if (figure.children.length === 2) {
figure.style.height = "18rem";
figure.style.borderRadius = "10px";
figure.style.background = "linear-gradient(to right, #935116, #FAE5D3)";
figure.style.color = "white";
figure.style.backgroundSize = "400% 400%";
}
}
}
This Pen doesn't use any external JavaScript resources.