Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

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

#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