Say you have the following CSS applied to a div tag
.divtagABS {
position: absolute;
margin-left: auto;
margin-right: auto;
}
the margin-left
and margin-right
does not take effect
but if you have relative, it works fine i.e.
.divtagREL {
position: relative;
margin-left: auto;
margin-right: auto;
}
Why is that? I just want to center an element.
Can someone explain why setting margins to auto in absolute position does not work?
margin: auto;
. with absolute position, all other style elements(regarding position/etc) are ignored. – Hautemarneposition: absolute;
on IE Edge. – Kaylenekayley