Centering divs in other containers it’s tricky for a lot of newbies. Below you will find the quickest and easiest way to center a div inside another div.
<div style=”width:100px; margin:auto”>Center text</div>
Notice I added 100% width to the parent div so it will be as wide as the browser screen. After that, the child div needs two things to be centered:
- A width. It can be in percent or pixel, doesn’t matter;
- Needs to have left and right margin set to auto;
This is it.