Doing some html horizontal center stuff, I just realized that I could use both things to center a box element into its parent, so my question is which of those 2 are better (in terms of performance, usability, etc).
Centering with margin: 0 auto; vs. justify-content and flexbox
8.5k views Asked by DevStarlight At
2
There are 2 answers
0
On
Because of the way margins are handled in flex, these do the same job.
But as a general practice, when you have more div's, using flex would do the job more accurately and will provide you choice for distributing the space equally".
When you have few div' , you can go with margin:auto
.
Remember flexbox provides us the choice for redistributing the space.
If you use
div
orp
it's better to usemargin: 0px auto;
for containers or main page, But if you need two or more children to be centered, it's better to set parent totext-align:center
and the children todisplay: inline-block
.