I am attempting to align the contents of a div to the center, with its parent container set to Relative.
Here is the CSS used for the inner div:
position: absolute;
margin: auto;
width: 70px;
height: 70px;
However, it does not align to the center as expected. I had to add left and right properties both set to 0, but I am unsure why.
position: absolute;
right: 0;
left: 0;
margin: auto;
width: 70px;
height: 70px;
I believed that alignment only required a width property, which is already defined.
I am puzzled by the fact that setting both right and left to 0 seems to correct the alignment issue.
Furthermore, if the image within the div is 70px, and the parent container is 200px wide (which it is), what effect does setting right and left to 0 have?
If you have any insights on this matter, please share them as I may not be interpreting it correctly.
Thank you.