Cascading cards


Our Split screen intro section and navigation are ready and we can move on to the next step. This time we will create the "My projects" section and add special, cascading cards to it.

Step 1 - add an empty "My projects" section

Inside the <main> section add a .container class with auto margins and padding. Then inside the .container add an empty "My projects" section with a heading. Also remove the hard-set .h-[500px] height in <main>, as we only used it for testing:

By the way, you will notice that the heading of the "My projects" section is too close to our intro above. Let's add a large bottom margin to the <header> section to make some space between them.

Step 2 - add grid with 3 columns

Add a grid with 3 columns (for large screens) inside. Nothing new to explain, we've done this many times before:

Step 3 - add a card to each column

From the cards documentation page, copy the Image with ripple sample code and insert it into each column.

Don't forget to add Ripple to your JavaScript initialization in your src/js/index.js file:

Step 4 - customize the content of the cards

Add texts and graphics to cards according to your preferences. I added the following:

Step 5 - add a margin to the image

To create the impression of cascade, we must first add some margins to the image wrapper.

Let's add the .mx-4 class to the <div> wrapping the image, to add some margin on the sides.

AI engine

Finished 13.09.2023 for Techify

Ut pretium ultricies dignissim. Sed sit amet mi eget urna placerat vulputate. Ut vulputate est non quam dignissim elementum. Donec a ullamcorper diam.

Step 6 - add shadows and roundings

To give the impression of an independent, cascading layer, the image should have its own shadow and roundings. We can achieve this by changing .rounded-t-lg class to rounded-lg class in the <img> element and adding .shadow-lg class to the wrapper of the image:

AI engine

Finished 13.09.2023 for Techify

Ut pretium ultricies dignissim. Sed sit amet mi eget urna placerat vulputate. Ut vulputate est non quam dignissim elementum. Donec a ullamcorper diam.

Step 7 - add a negative top margin

And now the most important detail - let's add a negative top margin to the image wrapper, to make it overlap the card.

To add a negative margin, we use normal spacing classes such as .mr-4 or .mt-5, but add - before them.

Now let's add .-mt-4 class to the image wrapper:

If you save the file, you will see that the entire class has moved up, instead of just the image. This is because we need also change the display property in our card from ..block to .inline-block

And now it works 🚀

AI engine

Finished 13.09.2023 for Techify

Ut pretium ultricies dignissim. Sed sit amet mi eget urna placerat vulputate. Ut vulputate est non quam dignissim elementum. Donec a ullamcorper diam.

Step 8 - adjust the height of the cards

As you can see, the middle card has a bit more text, making it taller.

It would definitely look better if, regardless of the amount of content, all cards kept the same height.

To achieve this we need to add the ..h-full class to each card.

And now they are equal:

Step 9 - adjust roundings

In this project, we use strong rounding of the corners. For the sake of consistency, let's replace the .rounded-lg classes with .rounded-xl to increase rounding in cards and images:

AI engine

Finished 13.09.2023 for Techify

Ut pretium ultricies dignissim. Sed sit amet mi eget urna placerat vulputate. Ut vulputate est non quam dignissim elementum. Donec a ullamcorper diam.

And that's it. Our cascading cards are ready!




John Doe

About author

Michal Szymanski

Co Founder at TW Elements and MDBootstrap / Listed in Forbes „30 under 30" / Open-source enthusiast / Dancer, nerd & book lover.

Author of hundreds of articles on programming, business, marketing and productivity. In the past, an educator working with troubled youth in orphanages and correctional facilities.