css absolute position won't work with margin-left:auto margin-right: auto

Posted by user1118019 on Stack Overflow See other posts from Stack Overflow or by user1118019
Published on 2012-04-03T17:22:25Z Indexed on 2012/04/03 17:29 UTC
Read the original article Hit count: 340

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about html

Related posts about html5