Design comparison
Solution retrospective
I used simple margins and padding in CSS to center the card in both mobile and desktop views. I wonder what are most 'common/best practices' for centering something like this card element I made. I imagine using flexbox would be easier and more responsive in the future so I'm eager to utilize my basic knowledge of that in another project.
Community feedback
- @denieldenPosted over 2 years ago
Hi George, great work on this challenge! 😉
Here are a few tips for improve your code:
- add
main
tag and wrap the card for improve the Accessibility img
element must have analt
attribute, it's very important!- remove all
margin
from.card
class - remove all
padding
from body - use flexbox to the body to center the card. Read here -> best flex guide
- after, add
min-height: 100vh
to body because Flexbox aligns child items to the size of the parent container - instead of using
px
use relative units of measurement likerem
-> read here
Overall you did well 😁 Hope this help!
Marked as helpful1 - add
- @MinhKhangTranPosted over 2 years ago
Hi George, nice solution!
If you want to center your card you can use
flexbox
on your body.For example:
body{ display: flex; min-height: 100vh; flex-direction: column; justify-content: center; align-items: center; }
For this to work you should delete your margins and paddings.
on your body: padding: 85px 25px; => padding: 0;
on your .card: margin: 110px auto; => margin:0;
I hope this helped.
Happy Coding and having fun doing it.
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