【问题标题】:Bootstrap 4 alpha 6 trying to create content that aligns top and bottom of rowBootstrap 4 alpha 6 尝试创建对齐行的顶部和底部的内容
【发布时间】:2017-07-14 01:04:46
【问题描述】:

引导程序 4 阿尔法 6

看这里https://v4-alpha.getbootstrap.com/layout/grid/#vertical-alignment

我也发现了这个:

https://v4-alpha.getbootstrap.com/utilities/flexbox/#direction

但到目前为止还没有运气

我尝试:

将元素对齐到行的顶部行的底部

它不需要在同一行。但我认为这是最简单的。由于每一行都是一个新的 flex 容器,我认为它的工作方式没有什么不同。

查看此代码笔 https://codepen.io/anon/pen/GEzBrw

@import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css' );

html,
body {
  height: 100%;
}

.container {
  min-height: 100%;
  height: auto;
  background-color: gray;
}

.my-top {
  background-color: salmon;
}

.my-bot {
  background-color: cornflowerblue;
}
<div class="container">
  <div class="row justify-content-between">
    <div class="col my-top">
      <p>Red container to the top (works)</p>
      <p>Red container to the top (works)</p>
      <p>Red container to the top (works)</p>
      <p>Red container to the top (works)</p>
      <p>Red container to the top (works)</p>
      <p>Red container to the top (works)</p>
    </div>
    <div class="w-100"></div>
    <div class="col my-bot  align-self-end">
      <p>Blue container to the bottom (doesn't work)</p>
      <p>Blue container to the bottom (doesn't work)</p>
      <p>Blue container to the bottom (doesn't work)</p>
      <p>Blue container to the bottom (doesn't work)</p>
      grey stuff in between. no hard coding with padding or such allowed
    </div>
  </div>
</div>

编辑

想要的输出

【问题讨论】:

  • 试图将元素对齐到底部的代码在哪里?到目前为止,代码仅突出显示元素。
  • 这个想法是justify-content-between 在元素之间添加空间。是的,但是很好的问题,在 bootstrap 4 文档中尝试将元素对齐到底部的代码在哪里?
  • 我的意思是我尝试了他们页面上的所有内容,但没有任何效果。我也可以放弃这些尝试。
  • Toskan,我在问你你的代码在哪里试图对齐底部的元素。
  • 没必要生气。 v4-alpha.getbootstrap.com/layout/grid/#vertical-alignment 我正在尝试使用 bootstrap 4 类将元素与底部对齐。分别证明元素之间的内容

标签: html css twitter-bootstrap flexbox bootstrap-4


【解决方案1】:

.row 也需要全高。您可以将h-100 类用于height:100%

https://www.codeply.com/go/EA6zTlQLxC

<div class="container h-100">
  <div class="row h-100">
    <div class="col my-top">
      <p>Red container to the top (works)</p>
      <p>Red container to the top (works)</p>
      <p>Red container to the top (works)</p>
    </div>
    <div class="w-100"></div>
    <div class="col my-bot align-self-end">
      <p>Blue container to the bottom (doesn't work)</p>
      grey stuff in between. no hard coding with padding or such allowed
    </div>
  </div>
</div>

【讨论】:

  • 我很惊讶它的工作原理......因为我已经在那里了,我想......你可以删除justify-content-between btw。无论出于何种原因都不需要它。
【解决方案2】:

使用flexboxsizing 类。

确保包含元素是父元素的全高(这里我假设它是视口的高度)。使用height: 100%; 时,您必须将height: 100%; 从根(html) 向下通过每个元素应用到目标元素.flex-column。如果您不这样做,.flex-column 元素将仅与内容一样高,并且无法伸展以提供空间。

@import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css' );

html,
body {
  height: 100%;
}

.container {
  background-color: gray;
}

.my-top {
  background-color: salmon;
}

.my-bot {
  background-color: cornflowerblue;
}
<div class="container h-100">
  <div class="h-100 d-flex align-items-end flex-column">
    <div class="w-100 my-top">
      <p>Red container to the top (works)</p>
      <p>Red container to the top (works)</p>
      <p>Red container to the top (works)</p>
      <p>Red container to the top (works)</p>
      <p>Red container to the top (works)</p>
      <p>Red container to the top (works)</p>
    </div>
    <div class="w-100 mt-auto my-bot">
      <p>Blue container to the bottom (doesn't work)</p>
      <p>Blue container to the bottom (doesn't work)</p>
      <p>Blue container to the bottom (doesn't work)</p>
      <p>Blue container to the bottom (doesn't work)</p>
      grey stuff in between. no hard coding with padding or such allowed
    </div>
  </div>
</div>

注意:查看代码 sn-p 时,请务必使用全屏选项。

【讨论】:

  • 问题是,身高对我没有帮助。我需要最小高度。高度需要自动以允许内容溢出或用于小屏幕
  • 我看到您想要更改以适应它的唯一.h-100 是与.container 共享的.h-100。为此,只需执行您之前所做的操作,.container { min-height: 100%; }
猜你喜欢
  • 2018-08-29
  • 2018-05-23
  • 2017-10-11
  • 2014-05-24
  • 2021-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-01
相关资源
最近更新 更多