Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

QR Code

@JordanKleinbaum

Desktop design screenshot for the QR code component coding challenge

This is a solution for...

  • HTML
  • CSS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


Question: I have an issue with CSS position, the way I centered my "card" div was by adding display: flex, align items and justify content to the entire body of the HTML Document. What is the best practice / easiest way to center the div, as well as center the text within the card?

Thank you!

Community feedback

P
doublem 530

@MarioMinchevski

Posted

Heya!

Congratulations on solving your first challenge!

Regarding the placement of your card in the center of the screen, you can also use

display: grid; place-content: center;

If this does not work, just set the body min-height: 100vh and it will be working for sure. It's a bit less code than using flex :)

Hope this helps, happy coding!

0

@LuisJimenez19

Posted

Hello, congratulations on finishing the challenge.

As you have done it is fine, if you do not want to add the style to the body then create another element that contains everything, but for this project it is fine.

It is always best to manipulate the content from its container. You can add the height to the body or to the min-heigth:100vh container element and with the flex rules you've added it should be perfectly centered so you don't use the margin on the card.

Another way to do that and with one less line is to use grid:

body {
    background-color: hsl(212, 45%, 89%);
    display: flex;
    min-height: 100vh;
    display: grid;
    place-content: center;
   
}

I hope my contribution is helpful, do not hesitate to ask if you have another question. 👋🏽

0

@Miracle656

Posted

try this div { width: 300px; height: 300px; background-color: red; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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