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. =)

http://stackoverflow.com/questions/8508275/how-to-center-a-position-absolute-element

Leave a Reply

Your email address will not be published.