Search code examples
htmlcssinternet-explorercss-floatinternet-explorer-7

How can I center div in div in IE7


HTML:

<div class="wrapper">
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
</div>

CSS:

.wrapper{
    width:1000px;
    text-align:center;
    float:left;    
}

.wrapper .box{
    width:300px;
    height:50px;
    display:inline-block;
    background:#F00;
    margin:0 10px 10px 0;
    overflow:hidden;
 }

I want to center all div in wrapper div like this;enter image description here

Above codes work fine in IE8,IE9,Chrome,Safari,Opera,FF but not working in IE7. When I open page in IE7, page looks like this;

enter image description here

If I use float:left, the problem seems to be solved but all divs based on the left. How can I solve this?

http://jsfiddle.net/eBxFX/2/


Solution

  • Inline-block doesn't work in IE7.

    You have to use zoom:1 and display:inline as a hack or without hack from a different css only for ie7.

    .wrapper .box{
        width:300px;
        height:50px;
        display:inline-block;
        *display: inline;
        *zoom:1;
        background:#F00;
        margin:0 10px 10px 0;
        overflow:hidden;
    }
    

    http://jsfiddle.net/eBxFX/4/