Why absolute positioning inside the container requires the container to be relative

It makes no sense to me.

If I want the div to remain: 20px; top: 20px from the edge of the container, I would have to do something like position: absolute-in-parent ;. Locating a child should not require modification to the parent.

At least it seems more modular and unleashes this way. And as a programmer, I was taught to possess this.

+7
source share
1 answer

Absolute positioning refers to what is called a containing block. The containing block is the closest parent that has relative or absolute positioning (which can be a body element if nothing else is found). This allows you to position an element relative to any of its parents. absolute-within-parent limit you only to being able to fully position the element relative to its immediate parent, which is not always what you need.

+8
source

All Articles