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

Responsive QR Code Page

meher-hexโ€ข 20

@meher-hex

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


What challenges did you encounter, and how did you overcome them?

This was a very easy challenge as it only required HTML and CSS, that too very basic knowledge. However, I still struggled with centering the main div. I haven't overcome it properly but I did try a temporary solution. I took help from a few popular websites such as Stack Overflow and W3Schools. Other than that, it was fun coding this!

What specific areas of your project would you like help with?

Centering the div. Whenever I use margin: auto or any other common solutions, it sits in the center but not exactly at the middle of the page. It's stuck to the top. That's what I need help with.

Community feedback

Atef Khaledโ€ข 80

@atefkhaled7

Posted

Great job on completing your first project on Frontend Mentor! Itโ€™s an exciting milestone, and I appreciate your effort. ๐Ÿ˜Š

Now, letโ€™s address the issue you faced with centering a <div>. Centering elements can be tricky, especially when youโ€™re just starting out. Here are some suggestions to improve your code:

Centering Elements:

  1. Consider using Flexbox or Grid for more consistent results.
  2. For horizontal centering, use justify-content: center; (Flexbox) or place-items: center; (Grid).
  3. For vertical centering, use align-items: center; (Flexbox) or place-items: center; (Grid).

CSS Reset: Consider using a CSS reset to remove default browser styles. This ensures a consistent starting point for your styling. EX: *{ margin: 0; padding: 0; box-sizing: border-box; }

You should add it first thing in the CSS file using the universal selector *{ } OR add it to the body { }

Remember, practice makes perfect! Keep experimenting, learning, and building more projects. Happy coding! ๐Ÿš€

Marked as helpful

1

meher-hexโ€ข 20

@meher-hex

Posted

@atefkhaled7 Thank you so much for your feedback! I've already used CSS Flexbox and added exactly what you suggested. Unfortunately, it never works for me or any other typical solutions. However, this is my first time hearing about CSS reset. Thank you for enlightening me on that. I'll make sure to use it on my next project.

1
Daniel ๐Ÿ›ธโ€ข 44,230

@danielmrz-dev

Posted

Hello, @meher-hex!

Your project is looking fantastic!

About your question:

Centering the div. Whenever I use margin: auto or any other common solutions, it sits in the center but not exactly at the middle of the page. It's stuck to the top. That's what I need help with.

  • Using margin isn't always the most effective method for centering an element.

Here's a highly efficient approach to position an element at the center of the page both vertically and horizontally:

๐Ÿ“Œ Apply this CSS to the body (avoid using position or margins in order to work correctly):

body {
    min-height: 100vh;
    display: flex; 
    justify-content: center;
    align-items: center;
}

I hope you find this helpful!

Keep up the excellent work!

Marked as helpful

1

meher-hexโ€ข 20

@meher-hex

Posted

@danielmrz-dev Hey there! I have used the exact code you suggested except for the min-height property. I'll try using it in my next project. Thank you so much for your feedback!

1

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