A. The inner box stays at the top-left corner with no offset.
B. The inner box moves 1.5rem up and 1rem left inside the relative container.
C. The inner box moves 6rem down and 4rem right inside the relative container.
D. The inner box moves 1.5rem down and 1rem right inside the relative container.
Solution
Step 1: Understand Tailwind spacing scale
top-6 means 1.5rem down, left-4 means 1rem right offset.
Step 2: Positioning context
The parent is relative, so absolute child offsets from parent's edges.
Final Answer:
The inner box moves 1.5rem down and 1rem right inside the relative container. -> Option D
Quick Check:
top-6 = 1.5rem down, left-4 = 1rem right [OK]
Hint: Absolute inside relative uses offsets from parent edges [OK]
Common Mistakes:
Thinking top-6 moves element up
Ignoring relative positioning on parent
Confusing left offset direction
4. Identify the error in this Tailwind usage:
<div class="absolute top-4 right-4">Hello</div>
when the parent has no positioning class.
medium
A. No error; offsets work relative to viewport by default.
B. The classes top-4 and right-4 are invalid.
C. Offsets won't work as expected because parent is not positioned.
D. The element must have relative class instead of absolute.
Solution
Step 1: Understand positioning context
An absolute element positions relative to nearest positioned ancestor.
Step 2: Check parent positioning
If parent has no position (static by default), offsets relate to viewport, which may cause unexpected placement.
Final Answer:
Offsets won't work as expected because parent is not positioned. -> Option C
Quick Check:
Absolute needs positioned parent for expected offsets [OK]
Hint: Absolute offsets need positioned parent (relative/absolute/fixed) [OK]
Common Mistakes:
Assuming offsets always relate to parent
Thinking classes are invalid
Confusing absolute with relative positioning
5. You want to place a notification badge 0.75rem from the top and 0.5rem from the right inside a relative container. Which Tailwind classes achieve this?
hard
A. top-3 right-2
B. top-2 right-3
C. top-4 right-4
D. top-6 right-1
Solution
Step 1: Match spacing scale to rem values
In Tailwind, 3 equals 0.75rem and 2 equals 0.5rem spacing.
Step 2: Assign correct classes for top and right offsets
Use top-3 for 0.75rem top offset and right-2 for 0.5rem right offset.
Final Answer:
top-3 right-2 -> Option A
Quick Check:
top-3 = 0.75rem, right-2 = 0.5rem [OK]
Hint: Use Tailwind spacing scale: 3=0.75rem, 2=0.5rem for offsets [OK]