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

I used basics of CSS like box model to solve this challenge

@suleosmann

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


  1. I tried to get the div container that is holding the whole content to center by winging the margin-left number, how could I had done better.
  2. I had a hard time it responsive for mobile view, I had to google it, Did I get close to doing correctly?

Community feedback

@SadeeshaJayaweera

Posted

Congratulations on completing the challenge & all the very Best ✌️

It sounds like you were trying to center a <div> container that holds your content by adjusting the margin-left property. While this approach can work in some cases, it may not be the most responsive and flexible way to achieve centering, especially for mobile views. There are more modern and responsive techniques you can use for centering content. Here's a better approach:

  1. Flexbox Centering: One of the most popular and responsive methods for centering content is using flexbox. To center a <div> horizontally and vertically, you can apply the following CSS to the container:

    .container {
      display: flex;
      justify-content: center; /* Center horizontally */
      align-items: center;     /* Center vertically */
    }
    

    This will work well for various screen sizes, including mobile, without having to set specific margin values.

  2. CSS Grid Centering: CSS Grid is another powerful tool for layout control. You can use it to center content as well. Here's an example:

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

    This will center the content both horizontally and vertically within the container.

  3. Margin: 0 auto for Block-Level Elements: If you want to center a block-level element (like a <div>) horizontally, you can also use the margin: 0 auto; technique. This method is useful when you want to center a block horizontally within its parent container.

    .container {
      margin: 0 auto; /* Center horizontally within parent */
    }
    

    To center vertically as well, you can combine this with flexbox or grid as mentioned above.

For responsiveness, it's also essential to consider using media queries to adjust your layout for different screen sizes. Media queries allow you to apply different CSS styles depending on the screen width, ensuring your content looks good on both desktop and mobile devices.

Here's a basic example of a media query for mobile responsiveness:

@media (max-width: 768px) {
  /* Your mobile-specific CSS styles go here */
}

Marked as helpful

1
NectarHub 30

@NectarHub

Posted

It will center horizontally and also some give margin-top .container{ margin : 0 auto; }

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