You can decrease the css value:
.absolute-center { position:absolute; width: 500px; height: 100px; margin: auto; top: 0; bottom: 0; right: 0; left: 0; border: solid 1px red; }
<p class="absolute-center">What is this sorcery?</p>
Absolute element with properties of type bottom: 0; top: 0; left: 0; right: 0; bottom: 0; top: 0; left: 0; right: 0; will fill all the space.
So what's the secret / witchcraft?
You determine the width and height of the element. Therefore, even if he wants to fill the entire space, he will be limited by your width and height.
Secret margin: auto , why? Because the element will fill in the remaining distance using the field. Thus, since you determined the width and height, it will have this size, but the margin will fill the rest of the container / parent with the auto method, equal to the size of both sides.
Due to margin:auto you need to determine the width and height.
Joel Almeida Jul 09 '15 at 8:18 2015-07-09 08:18
source share