Responsive profile card component main using CSS Grid layout
Design comparison
Solution retrospective
I found really difficult the way to center the card in smaller devices like mobile so I couldnt REALLY make it responsive as the scroll bars appear on both the side and the bottom, couldnt figure out how to remove it and apply the margin to center the card. Tried to do that with flex but as I did the whole card distorted...
If anyone could give me a tip on how to do that and generally if the code is decent.
Community feedback
- @dusan-bPosted almost 2 years ago
Hello Omri,
I just looked at your code and I like your approach. To make the card component responsive though, you should avoid specifying fixed widths and heights.
The following changes allow you to omit the media query for
card
completely:.card { width: 100%; max-width: 400px; /* Let the container responsively grow up to 400px */ padding-bottom: 40px; /* Instead of using a fixed height */ background-color: #fff; margin: 0 auto; /* 'margin: 160px auto' is not a good solution to center vertically */ border-radius: 10px; }
To center the card, just add these three rules to the
body
:body { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding-inline: 20px; /* Give some space on the sides, when screen width goes under 400px */ }
This way your card becomes responsive and is properly centered.
Hope this helps. Happy coding!
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