How to center a "position: absolute" element

user1098278 picture user1098278 · Dec 14, 2011 · Viewed 889.4k times · Source

I'm having a problem centering an element that has the attribute position set to absolute. Does anyone know why the images are not centered?

Answer

baaroz picture baaroz · Aug 28, 2013

If you have set a width you may use:

position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
text-align: center;