Mr. Harun’s order card between two neighbours: build transform functions and a transform-origin, then the corners the browser painted, its matrix, and a ghost…
Why it matters
transform and opacity are the two cheapest properties to animate because they trigger no new layout. Hovers, modals, carousels, toasts: all use them. Knowing the order of functions and transform-origin makes the result match what you pictured, instead of flying off somewhere odd.
The key idea
Each function works in the axes the ones before it left behind
Common mistakes
Swapping translate and rotate gives a different result Each function works in the axes the ones before it left behind. Want to move along the screen’s axes, then turn in place? Write translate() first, then rotate().
A moved element lands on its neighbour, and the neighbour does not make roomtransform only changes the painting; the layout box stays in its original slot, so neighbours are not pushed. If they must make room, change the layout (margin, gap, width). Remember too: a transformed element becomes the containing block of its position: fixed children.
A turn that does not pivot where you want rotate and scale pivot on transform-origin, the middle (50% 50%) by default. Move it to the corner or side that must stay still: transform-origin: left top for a menu opening from its button.
Try it in this playground
Add rotate, then translate, then swap them Use the arrow buttons on the function chips. Look at step 1’s ghost: its x axis is tilted too, so the translate after it runs at a slant.
Move the pin to a corner, then rotate The point at that corner stays, the rest swings round it.
Move the card over card B Use translate. The card lands on B, yet B’s offsetLeft does not change: layout does not know anything moved.
Type translate(-50%, -50%) Percentages in translate are of the card’s own size, not its parent’s. That is why this trick centres a position: absolute element.