Design comparison
Solution retrospective
I utilized grid-template-areas to create the perfect grid layout for the desktop view. I also timed myself while working on this component and was able to complete it in 1.5 hours, which was faster than I had anticipated. I chose to time myself in order to improve my time management skills and practice working under pressure.
What challenges did you encounter, and how did you overcome them?The cards don't have the same height as each other so initially the grid looked very jumbled. I fixed this by setting the height to 100% on the cards.
What specific areas of your project would you like help with?I would love to learn another efficient way to achieve this grid layout.
Community feedback
- @tedikoPosted 4 months ago
Hello @laura-nguyen! The reason why you need to explicitly set height to 100% on the cards is because of how you set your grid container in first place. The fr unit allows us to define grid tracks as fractions of the available space which means if a grid container has 2 rows with 1fr each, they will each take up an equal amount of space, i.e., each row will be 50% of the available space. You're defining
grid-template-rows: repeat(2, 1fr);
so both of your rows take up equal amount of space, and since your first row card content is bigger than second row cards it will still divide them with equal amout of space leaving second row with cards jumbled as you said. Instead what you want to use ismin-content
keyword which is the smallest size a box can take without overflowing its content - like so:grid-template-rows: repeat(2, min-content)
. This way, your second row will be as small as your largest card in that row. Now you can removeheight: 100%
from.card
container and from.card--5
where you setheight: 100%
andauto
within some breakpoint. Last thing you need to do is removealign-items: flex-start
because it is doing excatly what you want to avoid.align-items: flex-start
aligns items to be flush with the start edge of their cell and instead you want to fill the whole width of the cell withalign-items: stretch
. But since stretch is default behaviour (align-items: normal) you don't have to explicitly set that, just remove old property.Since you're using
display: grid
for<main>
on desktop you should be consistent and also usegrid
on mobile instead offlex
. Why switch between the two if one can do excatly the same?Have fun!
Marked as helpful0
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