Forums

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

Home Forums CSS Horizontally centering an absolute element Reply To: Horizontally centering an absolute element

#197513
Shikkediel
Participant

Got a step closer. No value in percentage would be of use to set margin because it is referring to the size of the containing parent and not to the element itself. So the longer the text, the higher the percentage would have to be to center the text. And no way to reliably do that even if it looks close enough. That’ll be one for jQuery I guess (but prefer CSS).

Hey, nice…

span {
display: inline-block;
position: relative;
left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%)
}

Pen that actually works!