Reputation: 619
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);
}
Upvotes: 0
Views: 92
Reputation: 2630
I just commented below positioning CSS:
/*
#theater-img img {
box-shadow: 0 0 20px 20px rgba(0, 0, 0, 0.5);
left: 50%;
position: absolute;
top: 50%;
}
*/
and then changed the postion to relative instead of absolute here:
#theater-img {
margin: 0;
padding: 0;
position: relative;
text-align: center;
}
Is it you wanted ??
Upvotes: 1
Reputation: 13
I saw your example link. I think use that codes after all images loaded.
jQuery:
$(window).load(function() {
$('#theater-img img').css({
'margin-top': '-' + $('#theater-img img').height()/2 + 'px',
'margin-left': '-' + $('#theater-img img').width()/2 + 'px'
});
});
and here's some css changes for your page. You should change #theater-img
HMTL:
#theater-img {
position: relative;
text-align: center;
margin: 0 0 46px 0;
padding: 0;
width: 100%;
height: 100%;
top: -46px;
z-index: -1;
}
Upvotes: 0
Reputation: 9075
Comment the following line in your bfx.viewer.js
:
image.css('margin', style['img-padding']+'px');
This is there the margin: 0px;
comes from.
Upvotes: 1