Skip to content

Position absolute

position: absolute pulls an element out of the flow, just like we saw with position: fixed.

However, instead of being positioned relative to the viewport. If you do not use any of the inset values, it will stay where it was in the normal flow, but other elements no longer “see” it, and they will slide under it.

Unlike position: fixed, rather than being positioned relative to the viewport, it is positioned relative to it’s nearest defined containing block. By default, this is the page itself.

Containing blocks come into play when we start using positioning. The containing block is what the inset properties are relative to.

When we use position: fixed, the viewport becomes the containing block.

When we use position: absolute, the containing block for that element is the nearest ancestor which has a position other than static. If there is no ancestor that has a position other than static, then it becomes the <html> element.

The main reason I use position: relative is to create a containing block for an absolutely positioned element.