【问题标题】:how put div center when use float使用浮动时如何放置div中心
【发布时间】:2015-01-20 12:35:58
【问题描述】:

里面有一个宽度为 100% 的 div 是另一个向左浮动的 div 怎么能把它放在中间?我尝试使用 margin 0 auto 但它不起作用

http://jsfiddle.net/cterh0sv/

.test {
    width:100%;
    height:120px;
    background:green;
}

.inside {
    margin:0 auto;
    width:100px;
    height:100px;
    background:white;
    margin:10px;
    float:left;
}
<div class="test">
    <div class="inside">
    </div>
    <div class="inside">
    </div>
    <div class="inside">
    </div>
</div>

【问题讨论】:

    标签: html css


    【解决方案1】:

    您必须删除浮动,将text-align: center 设置为容器,将display: inline-block 设置为项目。

    .test {
      width: 100%;
      height: 120px;
      background: green;
      text-align: center;
    }
    .inside {
      width: 100px;
      height: 100px;
      background: white;
      margin: 10px;
      display: inline-block;
    }
    <div class="test">
      <div class="inside">
      </div>
      <div class="inside">
      </div>
      <div class="inside">
      </div>
    </div>

    【讨论】:

      猜你喜欢
      • 2014-09-09
      • 2018-01-23
      • 1970-01-01
      • 1970-01-01
      • 2017-08-07
      • 2011-07-28
      • 2017-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多