Responsive QR-Code centralized with "position: absolute;"
Design comparison
Solution retrospective
Being able to code my first page without handholding. I would like to do it faster next time :-D
What challenges did you encounter, and how did you overcome them?The biggest challenge for me was centralizing the main element of the page while making it responsive, as said in the title I overcame this fixing the position to the center of the screen with the following snippet:
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
What specific areas of your project would you like help with?
I would like to know how to get the feel for the size of the things on the preview, this was also one of the things I had difficulty with.
Community feedback
- @rcsilva211Posted 2 months ago
The solution itself is great for this example, but from experience and after you've mentioned you fix to center the container, I can share that display: flex already does that for you :)
Here's my snippet:
.container { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; background-color: hsl(212, 45%, 89%); }
When setting the width and height to 100%, the container will occupy the entirety of its parent, in this case being the body. The display: flex will make it can be automatically be arranged keeping in consideration the elements inside; The justify-content: center will make it so it distributes the contents around the container (in this case, will place them to the center); The align-items: center will align all the contents of the flexbox in the vertical axis.
You can check W3Schools for more information about this: CSS Flexbox Container - W3 Schools
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