I am trying to position a <div>
always below anything else on the page. The <div>
is inserted using javascript and it is always the last element on the page before </body>
.
So far I have tried clear:both
and position:relative
which works really good but breaks if the content (above elements) are positioned absolute - Here is an example.
So what I am looking for is some css/js magic to always position a <div>
below anything else.
I don't know how much elements are above the injected <div>
and I don't know how they are positioned.
Unfortunately position:fixed
is not an option.
My Solution
I ended up doing it with help of javascript:
After inserting the absolute positioned <div>
element into the page I calculate the page height using the following function:
function getBodyHeight() {
var body = document.body, html = document.documentElement;
return Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
}
and set the top position depending on the body height:
element.style.top = (getBodyHeight())+"px";