Is there really no way to center an absolutely/relatively positioned element without javascript? I know it’s easy if the width of the element is dependable. Is there no CSS solution? Am I forced to resort to javascript?
<body><div class="parent"><div class="child">This stuff changes</div></div></body>
.child{margin:auto;position:absolute;left:50%} // this will center the left edge
.parent{width:800px;height:430px;margin:auto;overflow:hidden;}
How about:
Full demo html:
(source: http://solstice.co.il/blog/2008-02-26/horizontally-centering-content-dynamic-width-css)
For vertical centring also:
NB: the borders are just there to make it easier to see how things are laid out; the curvy corners are just nicer.
(source: http://blog.themeforest.net/tutorials/vertical-centering-with-css/)