<div class="grid">
	<div class="item">
		<p>Cupcakes</p>
		<div class="img-wrapper">
			<img src='https://images.unsplash.com/photo-1576618148400-f54bed99fcfd?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTY0OTE1MDYyNQ&ixlib=rb-1.2.1&q=80&w=400' alt='cupcake on yellow background'>
		</div>
	</div>
	<div class="item">
		<p>Muffins</p>
		<div class="img-wrapper">
			<img src='https://images.unsplash.com/photo-1575376356429-1144f4ce6a1d?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTY0OTE1MDk4Mw&ixlib=rb-1.2.1&q=80&w=400' alt='Muffins'>
		</div>
	</div>
	<div class="item">
		<p>Cookies</p>
		<div class="img-wrapper">
			<img src='https://images.unsplash.com/photo-1618923850107-d1a234d7a73a?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTY0OTE1MTIyNQ&ixlib=rb-1.2.1&q=80&w=400' alt='Cookies'>
		</div>
	</div>
	<div class="item">
		<p>Pastries</p>
		<div class="img-wrapper">
			<img src='https://images.unsplash.com/photo-1483695028939-5bb13f8648b0?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTY0OTE1MTI4Ng&ixlib=rb-1.2.1&q=80&w=400' alt='pain au chocolat'>
		</div>
	</div>
</div>
* {
	box-sizing: border-box;
}

body {
	font-family: Merriweather, serif;
	margin: 0;
	padding: 1rem;
	display: grid;
	place-items: center;
	min-height: 100vh;
	background: #1b1f21;
}

img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	transform: translate3d(100%, 0, 0);
	transition: transform 300ms;
	pointer-events: none;
}

.img-wrapper {
	position: relative;
	width: 100%;
	height: 100%;
}

.grid {
	--track: 1;
	display: grid;
	max-width: 85rem;
	width: 100%;
	transition: grid-template 300ms;
}

.item {
	--i: 0.5rem;
	--c1: deeppink;
	--c2: orange;
	
	background: repeating-linear-gradient(var(--a, 45deg), var(--c1), var(--c1) var(--i), var(--c2) var(--i), var(--c2) calc(var(--i) * 2));
	display: grid;
	place-items: center;
	grid-template: 1fr / 1fr var(--innerTrack, 0);
	overflow: hidden;
	aspect-ratio: 8 / 3;
	transition: filter 200ms;
}

.item:hover {
	grid-template: 1fr / 1fr var(--innerTrack, 0);
}

.item:hover img {
	opacity: 1;
	transform: translate3d(0, 0, 0);
}

.item:nth-child(2),
.item:nth-child(3) {
	--c2: darkorchid;
	--p: 50% 100%;
	background: repeating-radial-gradient(circle at var(--p), var(--c1), var(--c1) var(--i), var(--c2) var(--i), var(--c2) calc(var(--i) * 2));
}

.item:nth-child(3) {
	--p: 50% 0;
	--c1: cornflowerblue;
}

.item:nth-child(4) {
	--a: -45deg;
	--c1: cornflowerblue;
	--c2: turquoise;
}

.item p {
	background: black;
	color: white;
	padding: 0.5rem 0.75rem;
	font-size: clamp(1.1rem, 5vmin, 2.8rem);
	transition: opacity 300ms;
}

.grid:has(.item:first-child:hover) .item:not(:first-child),
.grid:has(.item:nth-child(2):hover) .item:not(:nth-child(2)),
.grid:has(.item:nth-child(3):hover) .item:not(:nth-child(3)),
.grid:has(.item:nth-child(4):hover) .item:not(:nth-child(4)) {
	filter: grayscale(10%) brightness(250%) contrast(30%);
}

.grid:has(.item:first-child:hover) .item:not(:first-child) p,
.grid:has(.item:nth-child(2):hover) .item:not(:nth-child(2)) p,
.grid:has(.item:nth-child(3):hover) .item:not(:nth-child(3)) p,
.grid:has(.item:nth-child(4):hover) .item:not(:nth-child(4)) p {
	opacity: 0;
}

@media (min-width: 50em) {
	.grid {
		grid-template: 1fr 1fr / 1fr 1fr;
		aspect-ratio: 2 / 1;
	}
	
	.item {
		aspect-ratio: auto;
	}
	
	.grid:has(.item:first-child:hover) {
		grid-template: var(--track) 1fr / var(--track) 1fr;
	}

	.grid:has(.item:nth-child(2):hover) {
		grid-template: var(--track) 1fr / 1fr var(--track);
	}

	.grid:has(.item:nth-child(3):hover) {
		grid-template: 1fr var(--track) / var(--track) 1fr;
	}

	.grid:has(.item:nth-child(4):hover) {
		grid-template: 1fr var(--track) / 1fr var(--track);
	}
}
const grid = document.querySelector('.grid')
const items = document.querySelectorAll('.item')

items.forEach((item) => {
	item.addEventListener('mouseenter', () => {
		gsap.to(grid, {
			'--track': '2fr',
			duration: 0.3,
		})
		gsap.to(item, {
			'--innerTrack': '1fr',
			duration: 0.3,
		})
	})

	item.addEventListener('mouseleave', () => {
		gsap.to(grid, {
			'--track': '1fr',
			duration: 0.3,
		})
		gsap.to(item, {
			'--innerTrack': '0fr',
			duration: 0.3,
		})
	})
})

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://unpkg.co/gsap@3/dist/gsap.min.js