onenonly Posted July 9, 2009 Share Posted July 9, 2009 I tried using CSS left: 50%; margin-left: <half image width>; But i need margin left to be dynamic because I will be using different images the width of each image is different so i need to change margin left everytime I tried using javascript document.getElementById('box').style.marginleft = myImage.width/2; this doesnt work any idea on best way of achieving this? Link to comment https://forums.phpfreaks.com/topic/165301-how-to-center-div-with-absolute-position/ Share on other sites More sharing options...
onenonly Posted July 9, 2009 Author Share Posted July 9, 2009 nevermind i got it var box = document.getElementById('box'); box.style.marginLeft = -myImage.width/2; including css with absolute position left:50%; Link to comment https://forums.phpfreaks.com/topic/165301-how-to-center-div-with-absolute-position/#findComment-871774 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.