3

When I set position: absolute and top: 0px the element does not actually positions absolutely, but it positions relatively to its parent (with position: relative).

Is there a simple way to set element position relative to the whole document not to the parent?

UPDATE

Can I do this if my element is already attached to a div with position:relative? It's a problem to reattach element to the body in my case.

1
  • Put it out of any parent div , only to be in the body. Commented Apr 2, 2013 at 9:54

2 Answers 2

2

If you want your div to be positioned absolute to parent than simply place it between the <body> tag (Here I assume that you are using position: relative for body) and not inside any positioned relative child element else your positioned absolute div will be positioned absolute to that element and not the body(Which you are referring as parent here)

Sign up to request clarification or add additional context in comments.

2 Comments

@AndreyMinogin position absolute has no relation with other element unless and until it is in a positioned relative div, absolute divs are out of the document flow
@AndreyMinogin If you want absolute to parent, there is no question of I CANNOT DO IT, it is absolute, place it anywhere but inside body tag and not any child of body. If you still need it, use higher negative top, right bottom left
1

An element with a position: absolute will position itself absolutely to the first parent element with another position style.

You need to bring the element outside any elements with position styles. You may as well put it at the end of the body HTML if it's going to be positioned absolutely anyway.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.