Performance: Position utilities (relative, absolute, fixed)
This affects how elements are layered and positioned on the page, impacting layout stability and paint performance.
Jump into concepts and practice - no test required
<div class="relative"> <div class="fixed top-0 left-0">Overlay</div> </div>
<div class="relative"> <div class="absolute top-0 left-0">Overlay</div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| relative positioning | none extra | minimal reflows | low paint cost | [OK] Good |
| absolute positioning inside relative container | none extra | multiple reflows if container resizes | medium paint cost | [!] OK |
| fixed positioning | none extra | no reflows on container changes | low paint cost | [OK] Good |
fixedfixed class keeps an element in the same place on the screen, even when scrolling.relative moves the element relative to its normal spot, absolute positions relative to nearest positioned parent, and static is default with no special positioning.fixed -> Option Afixed [OK]absolute with fixedrelative keeps element fixedstatic affects positionabsolute positioning align relative to it?absolute positioning is placed relative to the nearest ancestor that has a position other than static.relative makes it the reference for the child's absolute position.relative -> Option Drelative for child's absolute to work [OK]fixed on parent instead of relativeabsolute on parent mistakenlyabsolute top-0 left-0 to a child inside a parent with no position class in Tailwind?static.absolute positions relative to the page (viewport).absolute bottom-0 right-0 to it, but it doesn't stay fixed. What is the fix?absolute positions relative to nearest positioned parent and scrolls with page; fixed stays visible on screen during scroll.fixed instead of absolute.absolute to fixed on the button. -> Option Cfixed for always visible elements [OK]absolute expecting fixed behaviorrelative to parent instead of fixing buttondiv with relative class and inside it a span with absolute top-0 right-0. You want the span to stay fixed at the top right of the viewport instead. How do you change the classes?div is relative, so the span with absolute positions relative to it.span to fixed for viewport positioningspan relative to the viewport (screen), it needs fixed instead of absolute. The parent can remain relative.absolute on span to fixed and keep relative on div. -> Option Afixed on element to fix on viewport [OK]