When centering elements with dynamic widths, I typically use the code below:
.horz-vert-center {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
However, a common issue I face is that the element resizes prematurely. For example, a menu may transition to two lines when it could still fit on one:
https://i.sstatic.net/O6WHv.png
I find this confusing - if I am using percentage values, shouldn't the margins continue to decrease?
For a demonstration, check out this link: https://codepen.io/garethj/pen/LWdaRr