Flexbox keep equal height on vertically stacked boxes

This question already has an answer here:

  • Equal height rows in a flex container 8 answers

  • No...equal height only works on the same row...so when the elements wrap they no longer get the equal heights. If the flex-direction is column it CAN work provided there is enough vertical space for both of the elements to be the same height (2* the largest). If not, the container won't stretch to accomodate the two divs at the same size.

    .container {
      margin-bottom:10px;
      }
    
    .col-sm-6 {
      border:1px solid grey;
      flex:1;
    }
    .fixed {
      height: 250px;
    }
    .flex-container {
      display: flex;
      flex-direction: column;
    }
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
    <div class="container">
      <div class="row fixed flex-container">
            <a href="/#" class="box col-lg-3 col-md-4 col-sm-6">
           <h2>Same Height</h2>
           <div>sadsafmf sløfmkls</div>
         </a>
            <a href="/#" class="box col-lg-3 col-md-4 col-sm-6">
           <h2>Same Height</h2>
           <div>sadsafmf sløfmkls skldfsd ffsf sdflsdf f sl as ad sad</div>
         </a>
      </div>
    </div>
    
    <div class="container">
      <div class="row flex-container">
            <a href="/#" class="box col-lg-3 col-md-4 col-sm-6">
            <h2>Shorter</h2>
           <div>sadsafmf sløfmkls</div>
         </a>
            <a href="/#" class="box col-lg-3 col-md-4 col-sm-6">
           <h2>Taller</h2>
           <div>sadsafmf sløfmkls skldfsd ffsf sdflsdf f sl as ad sad</div>
         </a>
      </div>
    </div>

    Simply add align-self:stretch to the box element. Also height: 100% on the child may work.

    链接地址: http://www.djcxy.com/p/75652.html

    上一篇: 100%高度的嵌套式柔性体和元素上的滚动条(不是浏览器)

    下一篇: Flexbox在垂直堆叠的箱子上保持相同的高度