How to center a div using css

There are multiple ways to center a div, among them here are given an example of how to place a div in the center within a page.

Example 1:

div {
    width: 100px;
    height: 100px;
    background-color: red;

    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;

    margin: auto;

Example 2:

div {
    margin:0 auto;

Hope it helps!

Leave a Reply