HTML & CSS · Middle · Question 15 of 75
Why is transform: translate() often better than changing left on a position: absolute element for movement animations?
- ✓Correct answer:
translatedoesn't change layout, whileleftrecalculates layout every frame - 2
leftcan't be animated withtransitionor@keyframesat all - 3
translatesupports percentages, whileleftsupports only absolute pixels
Explanation
Moving via transform doesn't affect flow or trigger reflow, so the animation is smoother. left can be animated, but it's more expensive. Both support percentages, but they're computed differently: translate uses the element's own size (hence the translate(-50%, -50%) centering trick), left uses the containing block.