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? Quote 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%; Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.