开发者

How to change an element's position to absolute?

I'm trying to center a page on any resolution while still being able to use absolute positioning to move pictures. I figure that the best way would be to have a table positioned relatively in the beginning in the center of the page, then change it to absolute positioning in the onload of the page. I think the correct line is:

document.getElementById("Object").style.position = "absolute";

However, I put an alert box after it asking where the left side of the object is, I get undefined. But, if I directly assign it to a position (Object.style.left = 500) I will get that number. So I can assign it a value, meaning it is in absolute position, but I cannot pull a value o开发者_StackOverflowut of that.


use document.getElementById("elementName").offsetLeft to find the position of an object
relative to its parent-container's position [in your case, document.body]
You're accessing the CSS style object's left parameter, which is different.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜