Centering a “position: absolute” element

Sometimes we have a one-line div, having 3 elements. One floats to the left, one floats to the right, and one in the middle. The one in the middle often gets pushed around by the left/right element, resulting off-centered. related question.


The fix is to give the following css to the center div.

position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;

Thanks to the following link. =)

Leave a Reply

Your email address will not be published.