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

HTML Semantic, CSS

#accessibility
myrh 100

@myrhisyoinked

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 is the best practice to center elements horizontally and vertically?

Community feedback

Spirit 220

@git-ritesh

Posted

I often use display: flex;, align-items: center; & justify-content: center; to center things from both sides i.e. horizontally & vertically.

Though if I have to center a <div> only on the main axis then I use margin: 0 auto; to center but it should have a width for that to be happen as by default any <div> element is display: block; and it would take full width in the parent container.

2

@TANJIRWEBDEV

Posted

display: grid; place-content: center; thats it ! ez

2

Spirit 220

@git-ritesh

Posted

Does this center the content both vertically & horizontally using a single property place-content: center; Really it's cool! @TANJIRWEBDEV

0
Tharun Raj 240

@Code-Beaker

Posted

Hi there!

Congratulations on completing this project! 🎉

Here is the code that's commonly used for centering content horizontally and vertically:

.element {
  display: flex;
  justify-content: center;
  align-items: center;
}

Hope you find this helpful!

1

@mohammed-sarhad-ahmed

Posted

display:flex;
justify-content:center;
align-items:center
or 
display:grid;
place-content:center;
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