【问题标题】:How best to make this flexbox 100% height without specifying fixed height?如何在不指定固定高度的情况下最好地使这个 flexbox 达到 100% 高度?
【发布时间】:2016-02-13 11:48:37
【问题描述】:

我想将这 3 个 div 均匀地放在一个列中,但它们的父级 (.outer) 不会达到其他列内容的 100% 高度。我认为是因为它的父级没有设置固定的高度。

.container{
  margin-top: 60px;
}
 .container{
  border: 1px solid #000;  
}
.outer{
  border: 1px solid #000;
}

.row-center{
  height: 100%;
}

.outer{
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: 100%;
}

.one, .two, .three{
  flex: 0 0 40px;
  border: 1px solid #000;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>



<div class="container">
  <div class="row">
    <div class="col-xs-6"><img src="http://placehold.it/350x500"></div>
    <div class="col-xs-6 row-center">
      <div class="outer">
        <div class="one">some text</div>
        <div class="two">some text</div>
        <div class="three">some text</div>
      </div>
    </div>
  </div>
</div>

jsfiddle 镜像:https://jsfiddle.net/4mxfbody/2/

这里最好的程序是什么?我尝试过绝对定位.outer,但无法正常工作。

【问题讨论】:

    标签: html css twitter-bootstrap flexbox


    【解决方案1】:

    嵌套的弹性盒

    JSfiddle Demo

    * {
      margin: 0;
      padding: 0;
    }
    .container {
      border: 1px solid #000;
    }
    .outer {
      border: 1px solid #000;
    }
    .row {
      display: flex;
    }
    .row-center {
      display: flex;
      flex-direction: column;
    }
    .outer {
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      flex: 1;
    }
    .one,
    .two,
    .three {
      flex: 0 0 40px;
      border: 1px solid #000;
    }
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
    <div class="container">
      <div class="row">
        <div class="col-xs-6">
          <img class="img-responsive" src="http://placehold.it/350x500">
        </div>
        <div class="col-xs-6 row-center">
          <div class="outer">
            <div class="one">some text</div>
            <div class="two">some text</div>
            <div class="three">some text</div>
          </div>
        </div>
      </div>
    </div>

    【讨论】:

    • 如果将flex: 0 0 40px; 替换为flex: 1,每个 div 都会展开以均匀填充容器。 jsfiddle.net/4mxfbody/8
    猜你喜欢
    • 2023-03-22
    • 1970-01-01
    • 2014-11-14
    • 2010-12-18
    • 2010-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多