I am trying to center the contents of a div, my parent container is set to Relative.
I am using this on the inner div
position: absolute;
margin: auto;
width: 70px;
height: 70px;
but it refuses to center, i had to add a left and right of 0, but i don't understand why i.e.
position: absolute;
right: 0;
left: 0;
margin: auto;
width: 70px;
height: 70px;
I thought to center only requires a width, which is has.
I am a little confused at why setting the right / left to 0 - seems to work.
Also if the image is 70px and the parent box is 200px (which it is), setting right to 0 and left to 0 - what is this actually doing?
Any ideas, I am probably not understanding it correctly.
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…