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?
I've used this trick to center an absolutely positioned element. Though, you have to know the element's width.
Basically, you use left: 50%, then back it out half of it's width with a negative margin.