If you can change the <span> to <div>
<div id="rel"> <div id="abs">Why I'm not centered ?</div> </div>
Then this piece of CSS should work.
#rel { position: absolute; top: 10px; left: 20px; width: 400px; height: 300px; border: 1px solid red; text-align: center; } #abs { width: 300px; height: 200px; border: 1px solid blue; margin: auto; margin-top: 50px; }
I think itβs better to use automation for a closed box, as less changes are needed if you change the size of the container.
Jonas
source share