Bootstrap 4-将元素与其容器的底部对齐

时间:2018-09-03 15:25:56

标签: twitter-bootstrap alignment

我试图找到答案,但是没有运气,我自己也尝试了一些方法。 我在一行中有两列,我想将第二列的底部div(三个按钮组)垂直对齐到行容器的底部,即#control-panel。

当前第二列居中对齐(垂直),这就是为什么三个按钮未连接到容器底部的原因。

我还要附加一张图片,以便于查看 Attached image

 <div id="control-panel">
    <div class="container">
      <div class="row">

        <div class="col-lg-3">
          <div class="display-4 p-3"><h2>Step 3:</h2></div>
          <p>Add a contact form, if you like, so people can contact you!</p>
          <a href="" class="btn btn-primary">Show contact form</a>
        </div>
        <div class="col-lg-3 d-flex flex-column">
          <div class=" p-3"><h2>Step 4:</h2></div>
            <p>Pick a style for your website</p>
            <div class="btn-group align-self-bottom">
              <button class="btn btn-primary" type="button">Style 1</button>
              <button class="btn btn-secondary" type="button">Style 2</button>
              <button class="btn btn-primary" type="button">Style 3</button>
          </div>
        </div>
      </div>
    </div>
  </div>

容器的CSS只是:

#control-panel {
height: 200px
}

我想对要与底部对齐的“ btn-group”类使用“ align-self-bottom”或“ align-self-end”,但它会按水平方向而不是垂直方向移动

非常感谢任何建议

1 个答案:

答案 0 :(得分:0)

检查此StackBlitz:FlexBox example

enter image description here

HTML文件:

<div class="main-container">
  <div class="first-column">

  </div>

  <div class="second-column">
    <div class="buttons">

      <button>Button1</button>
      <button>Button2</button>
    </div>
  </div>
</div>

CSS文件:

.main-container {
  border-color: red;;
  border-style: solid;
  height: 100px;

  display: flex;
  flex-direction: row;
  justify-content: space-around;
}

.first-column {
  border-color: blue;;
  border-style: solid;
  height: 100px;
  width: 100px;
}

.second-column {
  border-color: green;;
  border-style: solid;
  height: 100px;
  width: 100px;
}

.buttons {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;

  height: 100px;
}

我在这里使用flexbox创建一个主容器(红色)并在其中创建两列(蓝色和绿色),然后在第二列中创建两个按钮并将它们与容器底部对齐。