How can I center div in div in IE7

故事扮演 提交于 2019-12-11 12:09:47

问题


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;

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;

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/


回答1:


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/



来源:https://stackoverflow.com/questions/14461917/how-can-i-center-div-in-div-in-ie7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!