Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Responsive four card feature section [NextJS, TypeScript, TailwindCSS]

Kenny Ng 400

@kennylun123

Desktop design screenshot for the Four card feature section coding challenge

This is a solution for...

  • HTML
  • CSS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


Hi everyone, this is my solution of "Four card feature section". This is my first time of using TypeScript and TailwindCSS. I want to ask a question about setting up the grid layout for desktop version in TailwindCSS. I can only use the original way to apply grid-area in global.css.

/* How to achieve below style in TailwindCSS? */
@media (min-width: 1024px) {
  .home__cards-wrapper {
    grid-template-areas:
      "card1 card2 card4"
      "card1 card3 card4";
    align-items: center;
  }

  .card:nth-of-type(1) {
    grid-area: card1;
  }

  .card:nth-of-type(2) {
    grid-area: card2;
  }

  .card:nth-of-type(3) {
    grid-area: card3;
  }

  .card:nth-of-type(4) {
    grid-area: card4;
  }
}
/* END: Card styles */

How would you set up the grid layout for cards of desktop version with TailwindCSS?

Any comment will be appreciated. Thanks for your help!! :D

Community feedback

T
Grace 29,310

@grace-snow

Posted

You would place the grid row/column/span properties individually I think

There are plugins for named template areas but it's not available "out of the box" to my knowledge

Ps your media query needs to be defined in rem or em not px

1

Kenny Ng 400

@kennylun123

Posted

@grace-snow

Aha! Instead of trying grid-template-area, I can achieve the same result by taking your advice of using the properties like grid-flow-col, row-span etc... Also I used arbitrary variant to select nth of type card to span between grid and vertically align center.

.home__cards-wrapper {
  ... grid-flow-row lg:grid-flow-col lg:[&>*:nth-of-type(1)]:row-span-2 lg:[&>*:nth-of-type(4)]:row-span-2 lg:items-center ...
}

Thank you so much! :D

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord