Vertically and Horizontally Align Any Element with CSS3 Transforms

A super simple and foolproof way of centering anything. It works with relative or absolute positioning, which makes it more versatile than other methods I’ve seen.

Note: if you’re using position relative to horizontally align your element, it must have a definite width

See the Pen Horizontal and Vertical Align Anything by Amber Weinberg (@amberweinberg) on CodePen.