Cu1ture
Cu1ture

Reputation: 1283

Why can't a 'position: absolute' element be positioned in relation to a parent that is 'position: static'?

Could someone explain the reason why a position: absolute; can only be positioned in relation to its nearest non - position: static; parent?

What is the reason the element can not be positioned in relation to its position: static; parent?

Upvotes: 7

Views: 1479

Answers (1)

neatnick
neatnick

Reputation: 1508

I believe that the reasoning behind this is so that you can position absolute elements relative to elements that are not just that element's direct parent. Since position: static is the default, it makes sense to have it be the determining factor on whether the element should position itself relative to that parent.

For example, I could use the following html to position an element relative to its grandparent:

<div id="grandparent" style="position:relative">
    <div id="parent">
       <div id="child" style="position:absolute;top:0">
       </div>
    </div>
</div>

Upvotes: 6

Related Questions