Centralizing a floating element :(

Posted by 2x2p1p on Stack Overflow See other posts from Stack Overflow or by 2x2p1p
Published on 2010-05-17T23:41:27Z Indexed on 2010/05/18 0:00 UTC
Read the original article Hit count: 265

Filed under:
|
|

Hi guys :|

My "div" element have a relative width, it isn't absolute so I can't use exact numbers to centralize. A nice solution is to use "display: inline-block":

body {
    text-align: center;
}

#myDiv {
    border: 1px solid black;
    display: inline-block;
    padding: 50px;
}

But this element NEEDS to float, I tried this:

#myDiv {
    border: 1px solid black;
    display: inline-block;
    float: left;
    padding: 50px;
}

And this:

#myDiv {
    border: 1px solid black;
    display: inline-block;
    padding: 50px;
    position: absolute;
}

Without any success, can somebody help me ?

Thanks

© Stack Overflow or respective owner

Related posts about css

Related posts about float