The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › CSS › postion: absolute
How center an image if there is position: absolute; ? When I’am trying use margin: 0 auto; it’s centering but when using margin and absolute, margin won’t work.
Try this.
img { position: absolute; margin: 0 auto; left: 0; right: 0; }
img { position: absolute; left: 50%; margin-left: -(usehalfofimgwidth)px; }
see also: https://css-tricks.com/snippets/css/absolute-center-vertical-horizontal-an-image/