You may have seen this question, center a div, or whatever, in interviews or other places. I am sure there are other approaches than I am sharing here, but I found these two cool ideas from multiple places (see refs at the end). These are not my original ideas so I will be sure to share where I learned these from: Using display:flex Make sure you know how flex works, but to do centering with flex, it's ridiculously simple: div .container { display : flex ; justify-content : center ; /* horizontal alignment */ align-items : center ; /* vertical alignment */ flex-direction : column ; /* since we are doing a vertical column */ padding : 1rem 3rem ; /* not related to centering */ } Now everything inside <div class="container"> </div> will be centered in both directions! Using display:grid You are so going to thank for me this one, you are welcome. This one is so simple it does not even need an explanation does it? div .conta...
I want to learn something new every day, but can I?