Member-only story

Expanding cards with CSS

Aneeqa Khan
1 min readSep 27, 2022

I saw a brilliant course by Florin Pop on YouTube and wanted to try some projects myself.

Overview

Create a cards of pictures and expand that card on hover.

Implementation

I started by placing five pictures in one section.

  <section>
<img src="assets/hawai.webp" />
<img src="assets/bamboo-forest.webp" />
<img src="assets/cappadocia.webp" />
<img src="assets/Lake-Croatia.webp" />
<img src="assets/mount-fuji.webp" />
</section>

and styled it

    section {
display: flex;
flex-direction: row;
}
img {
width: 50px;
height: 340px;
object-fit: cover;
border-radius: 40px;
margin-right: 10px;
cursor: pointer;
}

Images will begin showing just like this

Now I added :hover selector with width property and increased the card width. I have also added a transition property to make it smooth.

img {
...
transition: width 0.5s ease-in-out;
}
img:hover {
width: 400px;
}

and that’s it! You get very pleasing expanding cards.

Thank you for reading!
Feel free to connect on Twitter

--

--

Aneeqa Khan
Aneeqa Khan

Written by Aneeqa Khan

I’m a frontend web and mobile developer specialized in web/mobile designs and frontend frameworks. I usually work with React, React Native, Next and TypeScript.

Responses (2)