Home > Article > Web Front-end > css article absolute positioning element centering techniques
Generally, the absolute positioning element is centered, left:50%;top:50%; the effect can also be achieved by using negative margin or transform.
I discovered another trick today. Use top, left, right, and bottom to set the value to 0, and then magin:auto to achieve centering.
Reason:
<div class='box> <div class='jz'></div> </div>
div.box{ position: relative; height: 300px; background: #989eaa; } div.fz{ width: 100px; height: 100px; background: #499682; position: absolute; top:0; left: 0; right: 0; bottom: 0; margin:auto; }
For more css articles on absolute absolute positioning element centering techniques, please pay attention to the PHP Chinese website for related articles!