引导程序'align-content-around'不起作用

时间:2019-04-05 06:13:59

标签: html css css3 flexbox bootstrap-4

为什么align-content: space-around在这里不工作?解决方法是什么?需要将第3列和第4列对齐到底部。

.row {
  background: #f8f9fa;
}

.col {
  border: solid 1px red;
  padding: 10px;
  height: 200px;
}

.col-sm-6 {
  border: 1px solid green;
}
<script type="text/javascript" src="//code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<link rel="stylesheet" type="text/css" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script type="text/javascript" src="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">


<div class="container">
  <div class="row">
    <div class="col">
      1 of 2
    </div>
    <div class="col">


      <div class="row align-content-around">
        <div class="col-sm-6">
          1
        </div>
        <div class="col-sm-6">
          2
        </div>
        <div class="col-sm-6">
          3
        </div>
        <div class="col-sm-6">
          4
        </div>
      </div>

    </div>
  </div>
</div>

提琴-https://jsfiddle.net/afelixj/y9perjhf/

1 个答案:

答案 0 :(得分:2)

您的row具有 auto 高度-向其中添加height: 100%h-100类-请参见下面的演示

.row {
  background: #f8f9fa;
}

.col {
  border: solid 1px red;
  padding: 10px;
  height: 200px;
}

.col-sm-6 {
  border: 1px solid green;
}
<script type="text/javascript" src="//code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<link rel="stylesheet" type="text/css" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script type="text/javascript" src="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">


<div class="container">
  <div class="row">
    <div class="col">
      1 of 2
    </div>
    <div class="col">
      <div class="row align-content-around h-100">
        <div class="col-sm-6">
          1
        </div>
        <div class="col-sm-6">
          2
        </div>
        <div class="col-sm-6">
          3
        </div>
        <div class="col-sm-6">
          4
        </div>
      </div>
    </div>
  </div>
</div>