Home › Forums › CSS › centering absolutely positioned elements with left: 50% and -33% left margin › Reply To: centering absolutely positioned elements with left: 50% and -33% left margin
June 17, 2014 at 12:22 pm
#173005
Paulie_D
Member
There is a CSS3 alternative to
margin-left: /* (half the element width) */
It’s
transform:translateX(-50%);
If you need vertical center you can use transformY(-50%)
in conjunction withtop:50%
.
Here’s a codepen where I use both combined into a single property
transform:translate(-50%, -50%);
http://codepen.io/Paulie-D/pen/BGkcr
Support – http://caniuse.com/transforms2d