CSS Center Div Horizontally

May 26, 2019

Solution 1

<div style="width: 400px; margin:0 auto;">
  <div style="background-color: yellow; text-align: center;">
    Center Me
  </div>
</div>

Solution 2

<div style="text-align: center;">
  <div style="background-color: yellow; display: inline-block; width: 400px;">
    Center Me
  </div>
</div>
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.