Design comparison
Solution retrospective
i hope it all good now.
Community feedback
- @correlucasPosted about 2 years ago
๐พHi Mustapha, congrats on completing this challenge!
The approach you've used to center this card vertically is not the best way, because using margins you don't have much control over the component when it scales. My suggestion is that you do this alignment with
flexbox
using the body as a reference for the container.The first thing you need to do is to remove the margins used to align it, then apply
min-height: 100vh
to make the body height size becomes 100% of the screen height, this way you make sure that whatever the situation the child element (the container) align the body withdisplay: flex
andalign-items: center
/justify-items: center
.remove the margins:
.display { display: flex; flex-direction: column; background-color: hsl(0, 0%, 100%); width: 17rem; align-items: center; justify-content: center; margin: auto; /* margin-top: 5rem; */ /* padding: 0.8rem; */ border-radius: 0.5rem; }
USE FLEX AND MIN-HEIGTH TO ALIGN:
body { display: flex; background-color: hsl(212, 45%, 89%); min-height: 100vh; align-items: center; justify-content: center; flex-direction: column; }
Your html code is not optimized yet, since its too long and have some unnecessary elements. To make it clean you start by removing some unnecessary
<div>
. For this solution you wrap everything inside a single block of content using<div>
or<main>
(better option for accessibility) and put inside the whole content<img>
/<h1>
and<p>
.<body> <main> <img src="./images/image-qr-code.png" alt="Qr Code Image" > <h1>Improve your front-end skills by building projects</h1> <p>Scan the QR code to visit Frontend Mentor and take your coding skills to the next level</p> </main> </body>
โ๏ธ I hope this helps you and happy coding!
Marked as helpful1@Farouk-ayoPosted about 2 years ago@correlucas that was a wrap of it all.Thanks You Lucas.
0 - @hyrongennikePosted about 2 years ago
Hi @eff-r-k,
Congrats on completing the challenge
Just a suggestion, you can add the following to center the card in the middle of the page.
body { display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 100vh; } .display { margin: 0; }
Hope this is helpful
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