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
Request path contains unescaped characters
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Responsive QR Code

@sajeell

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


Vertically center a div is really hard

Community feedback

@quintin156

Posted

I know one simple way to center a div. Checkout https://web.dev/patterns/layout/ This website has taught me so many layouts just with simple css

(parent container)

.container { display: grid; place-items: center: height: 100vh; }

(children container)

.card { / properties for your card / }

Marked as helpful

1

@sajeell

Posted

@quintin156 Thank you.

0
Lucas 👾 104,420

@correlucas

Posted

👾Hi Sajeel Ahmad, 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 with display: flex and align-items: center / justify-items: center.

body {
    min-height: 100vh;
    background-color: var(--light_gray);
    font-family: 'Nunito Sans', sans-serif;
    font-size: 15px;
    display: flex;
    justify-content: center;
    align-self: center;
    display: flex;
    align-items: center;
}


}
.card {
    display: flex;
    border-radius: 20px;
    background-color: var(--white);
    flex-direction: column;
    padding: 1em;
    padding-bottom: 1.5em;
    align-items: center;
    /* position: absolute; */
    /* top: 0; */
    /* bottom: 0; */
    /* left: 0; */
    /* right: 0; */
    /* margin: auto; */
    width: 250px;
    height: 400px;
}

✌️ I hope this helps you and happy coding!

1

@sajeell

Posted

@correlucas Thank you.

1
Lucas 👾 104,420

@correlucas

Posted

@sajeell You're welcome Sajeel! Then say me if worked for you =)

0

@sajeell

Posted

@correlucas This really worked. You can check the code. Hurrah :fire:

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