grid-template-areas solution with Next.js, TailwindCSS, CSS module
Design comparison
Solution retrospective
I made various efforts to enhance the reusability of components,
like:
- storing the card's content information (title, logo, description) as an array of data, allowing it to be flexibly passed as arguments to the card component.
- using grid-template-area to handle changes in screen width only with the parent element of the card.
- using round and overflow-hidden class to make cards round.
I needed to change the card layout between the mobile and desktop versions, but achieving this with "flex" was challenging, so I decided to use "grid". While it’s possible to achieve the desired layout with grid-row and grid-column, it would require writing different conditional logic for each card, which would reduce the reusability of the component and make it difficult to process the array data using the map function. I wanted the parent element of the cards to have full control over the layout without adding layout-specific classes to each card. Therefore, I used grid-template-areas to allow the parent element to handle the layout adjustments based on screen size. Since grid-template-areas isn't available as a utility in TailwindCSS, I resolved this by using CSS modules.
Community feedback
- @YacoubDweikPosted about 1 month ago
Hey Ryo!
Amazing man! it's almost the same as the original design!
I would only say that from 935px to 768px you will see the cards behave differently depending on their text, I mean some of them will have different heights than the other, you can solve this issue for example by giving the p element fixed heights, because they are the problem here, you can give them height = their content + the needed padding || and make the padding 0 || there are some other solutions as well but you should have fixed heights in all cases, you can make the padding responsive using any responsive units, you can also make the font responsive as well using the same technique, but all in all well done man it is amazing and keep it up!
Marked as helpful1
Please log in to post a comment
Log in with GitHubJoin 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