Three-column-preview-card-component using CSS Grid

Solution retrospective
This is my solution to the 3-column challenge, I used CSS grid and Flexbox, it was a simple project but the heights and spacing between elements were a challenge since it isn't as simple as a space-between or space-around. How would you do it? would you use a single div or multiple ones? Answer would be very appreciated.
Please log in to post a comment
Log in with GitHubCommunity feedback
- @elaineleung
Hi Oubaid, I think you did a great job :) I did this challenge a while back, I just had a look at it to see what I did; I saw that I mainly added margin at the bottom of elements to space them. I'm pretty sure if I were to do it again, I'd definitely do things differently. For the desktop view, I would use flexbox with gap to space out things (since flexbox gap has over a 90% usage by now), and then for the last item, I'd put a
margin-top: auto
to push it to the bottom, a bit like this:.card { min-height: 30rem; } section { display: flex; flex-direction: column; gap: 1rem; // or margin-bottom: 1rem instead } .cta { margin-top: auto; }
For the HTML, it'll just be pretty straightforward, probably no containers since none of the children need more containers for alignment.
<section> <img> <h2></h2> <p></p> <a href="#" class="cta"></a> </section>
Once again, well done, and great questions for discussion 🙂
Marked as helpful - @Shard-Codes
Hello Oubaid, You great job on the challenge
Here are some tips to improve your solution.
- On the body tag add a min-height of 100vh like this.
body { background-color: var(--clr-very-light-gray); display: flex; justify-content: center; align-items: center; padding: 0; min-height: 100vh; /* Add this */ }
- On your container div remove the margin and min-height you set like this.
.container { display: grid; overflow: auto; margin: 5rem 1.5rem; /* Remove this */ grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); min-height: 30rem; /* Remove this */ border-radius: 0.5rem; }
And also remove the min-height on your column element, as well.
And with that, you should be set Happy coding 😊
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