I am centering a element inside a div horizontally and vertically, however the jQuery CSS code seems to be only resulting in style="margin: 0px" any ideas?
jQuery:
image.css({
'margin-top': '-'+(style['img-width']/2)+'px',
'margin-left': '-'+(style['img-height']/2)+'px',
});
Alternatively I tried:
image.css({
'marginTop': '-'+(style['img-width']/2)+'px',
'marginLeft': '-'+(style['img-height']/2)+'px',
});
CSS:
#theater-img {
position: absolute;
text-align: center;
margin: 0;
padding: 0;
}
#theater-img img {
position: absolute;
top: 50%;
left: 50%;
-webkit-box-shadow: 0 0 20px 20px rgba(0,0,0,0.5);
box-shadow: 0 0 20px 20px rgba(0,0,0,0.5);
}

topandleftsince your image is already on absolute position.image? Is it constructed in jQuery? Do you get any console errors?imageis the image tag. It's used multiple times. I added a link to the src.