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:

CSS
div { width: 100px; height: 100px; background-color: red; position: absolute; top:0; bottom: 0; left: 0; right: 0; margin: auto; }

Example 2:

div {
    width:100%;
    margin:0 auto;
}

Hope it helps!

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *