transform: translateY magically perfect center

Hey, I have a question, when we apply flex box center properties using align items (or justify content if flex direction = column), our center essentially starts from the top of first element. As a result, we dont get perfectly centered elements. But, the moment we put translateY(-50%), its perfectly centered, I would appreciate a good explanation on what exactly is this percentage about? that -50% puts it in center: https://codepen.io/latuza/pen/PwPyPXJ (uncomment line 12 to see what im saying)
anon
CodePen
Untitled
...
2 Replies
brr
brrOP2d ago
Is the percentage about the height of the element? so -50% means im getting -100px if the height was 200px? and that centers it?
mino
mino2d ago
yes the percentage transform: translateY -50% is relative to the element’s own size, not the parent.

Did you find this page helpful?