Performance: Negative margin usage
Negative margins affect layout calculation and can cause layout shifts impacting visual stability.
Jump into concepts and practice - no test required
<div class="-m-2">...</div><div class="-m-10">...</div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Large negative margin (-m-10) | No extra DOM nodes | Multiple reflows due to layout shifts | High paint cost from overlapping elements | [X] Bad |
| Small negative margin (-m-2) | No extra DOM nodes | Single or no reflow, stable layout | Low paint cost, no overlap | [OK] Good |
-m-4 do to an element?m-4 means margin of 1rem (16px) on all sides.-m-4 means negative margin of 1rem, pulling the element outward.-mt-2 for negative top margin.-mt-2 matches the correct syntax. Others are invalid.<div class="bg-blue-200 p-4"> <div class="bg-red-400 -ml-6 w-24 h-24">Box</div> </div>
-ml-6 meaning-ml-6 applies a negative left margin of 1.5rem (24px), pulling the element left outside its container.<div class="w-32 h-32 bg-green-300">Box 1</div> <div class="w-32 h-32 bg-yellow-300 ml--8">Box 2</div>
-ml-8, not ml--8.ml--8 is invalid and will not apply any margin, so no overlap occurs.-mt-4 applies a negative top margin of 1rem, pulling the image up to overlap.