CSS Position

Absolute

An absolutely positioned element will position itself relative to the nearest positioned ancestor. We can then modify its final position by setting the top, bottom, left and right properties. If no ancestor elements are explicitly positioned, the element will be displayed outside of the <html> element and be positioned relative to the viewport.

Viewport

Code and Preview

Description

Notice how the absolutely positioned element (green box) is positioned relative to the viewport of the frame because it doesn't have any explicitly positioned ancestors. Its final position ends up covering most of the first red box.

Editor
Preview

Positioned ancestor

Code and Preview

Description

Notice here how the absolutely positioned element (star inside the green box) is positioned relative to the nearest explicitly positioned ancestor (green box). Try setting the position of .star back to static and see what changes.

Editor
Preview