views:

55

answers:

1

Hi,

Just wondering if there's a way to position a div with absolute so that it ignores EVERYTHING else, if my site clears floats it seems divs that are created with Javascript and absolute positioning are still effected by it, is there any way to make them ignore EVERYTHING else and go exactly where I set them, regardless?

+2  A: 

position: absolute means that the object is positioned in context of it´s closest positioned ancestor element or the viewport if no ancestor element is positioned. So put your absolute positioned elements as direct children to the body element and you´ll be fine.

anddoutoi
This is my problem, I am creating them directly under the body, outside of all other elements (eg: <body><div id="absolutediv"></div><div id="another"></div></body>) but in some situations it doesn't work, the "another" div pushes the absolute div away, I want the absolutediv to always be in the same position, regardless of the others position. I guess I might to use z-index?
citricsquid
What do you mean by "pushes" the div away? If they're both have position: absolute they won't affect each other's position. They might overlap, but never move them. Can you post some code?
Tom
Put the objects created by javascript in the end of the document. Where your objects go in the code matters in this case. z-index only works on **positioned elements**.
anddoutoi
citricsquid
@citricsquid — I am unable to replicate your results. In the FireBug console, I used DOM methods to create a div, gave it a `width` and `height` of "100px", a `background` of "red", a `top` and `left` of "200px", and a `position` of "absolute", then appended it to the body. It appeared, as expected, 200 pixels away from the top and left edges of the page.
Ben Blank