Design comparison
Solution retrospective
I was wondering if there's a better way to implement centring the page vertically.
Community feedback
- @iammiracle01Posted over 2 years ago
Hi Muhammad, nice solution using CSS flex. By the way a better way for centering the page vertically is by including the following into your container styles:
- display:flex into
- set the flex-direction:column;
- then use the align-items:center to properly center your container on the page.
You can also add margin: 5rem auto .
Lastly, I'd suggest you remove the width and text-align property on your body tag.
Hope this helps, happy coding.
0 - @ziy-egPosted over 2 years ago
I love your code.
about your question for centering any item: try this code: <code> position: absolute; top: 50%; left: 50%; </code> this code will put the left-top corner of the item on the page center, so to make it work on the whole item you have to add another code to it.
<code> transform: translate(-50%, -50%); </code> that would move the left-top corner 50% up and left making the center point of the item in the center of the main container.. (makes it look like dealing with the center point)keep the good work..
0
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