Center Horizontally an element with absolute positioning.

By | August 4, 2015

Today I show you a little css trick i used to horizontally center a button defines in absolute position.
The following conventional technique is not walking in relative position:

div {
    position: relative;
    width: 50px;
    margin: auto;

Here is how to do the same in absolute position.

div {
    left: 0
    right: 0
    margin: auto;

Defining the left and the right of the element acts as if it has a defined width. This allows the browser to center the element horizontally.

See you soon


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.