How to create equal-height columns using Materialize and Flexbox?

大兔子大兔子 提交于 2019-12-02 18:16:55

问题


I am trying to use Flexboxes in order to strech a panel I created using Materialize.

This is the html that creates my panels:

<div class="row">   
    <div class="col s6">
        <div class="card-panel">
            panel1
        </div>
        <div class="card-panel">
            panel2
        </div>
        <div class="card-panel">
            panel3
        </div>
    </div>
    <div class="col s6">
        <div class="card-panel">
            panel4
        </div>
    </div>
</div>

And this is the result:

Now I would like to strech panel4 in order to make it flush with the bottom of panel3.

Probably this is possible using Flexbox but I can't figure out how to get Materialize and Flexbox to work together


回答1:


Materilize uses floats which will be negated under flexbox, so we will have to lay out each column separately using flexbox and flex-direction:Column.

Then we tell each card-panel to be to take upas much space as it can using flex:1.

Like so:

.row {
  display: flex;
}

.col {
  display: flex;
  flex-direction: column;
}

.card-panel {
  flex: 1;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" rel="stylesheet" />
<div class="row">
  <div class="col s6">
    <div class="card-panel">
      panel1
    </div>
    <div class="card-panel">
      panel2
    </div>
    <div class="card-panel">
      panel3
    </div>
  </div>
  <div class="col s6">
    <div class="card-panel">
      panel4
    </div>
  </div>
</div>


来源:https://stackoverflow.com/questions/54198937/how-to-create-equal-height-columns-using-materialize-and-flexbox

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