Performance: Top, right, bottom, left offsets
This concept affects layout and paint performance by changing element positioning and triggering reflows.
Jump into concepts and practice - no test required
<div class="relative"> <div class="transform translate-x-10 translate-y-10">Box</div> </div>
<div class="relative"> <div class="absolute top-10 left-10">Box</div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using top/right/bottom/left offsets with position | Low (few nodes) | Triggers reflow on offset change | Medium (repaint affected area) | [!] OK |
| Using CSS transform translate for movement | Low | No reflows triggered | Low (composite only) | [OK] Good |
relative positioning?4 equals 1rem spacing.bottom-4 moves the element 1rem down from the top edge when positioned.bottom-4 -> Option Bbottom- plus spacing number [OK]8 equals 2rem in Tailwind.left-8 moves element 2rem to the right from its container edge.left-8 -> Option Aleft- plus spacing number [OK]right-2 which is 0.5rem, not 2rem<div class="relative"> <div class="absolute top-6 left-4">Box</div> </div>
top-6 means 1.5rem down, left-4 means 1rem right offset.relative, so absolute child offsets from parent's edges.<div class="absolute top-4 right-4">Hello</div>when the parent has no positioning class.
absolute element positions relative to nearest positioned ancestor.relative container. Which Tailwind classes achieve this?3 equals 0.75rem and 2 equals 0.5rem spacing.top-3 for 0.75rem top offset and right-2 for 0.5rem right offset.top-3 right-2 -> Option A