【问题标题】:How to align element to bottom in a Bootstrap column?如何在 Bootstrap 列中将元素与底部对齐?
【发布时间】:2018-01-06 16:56:30
【问题描述】:

我需要将一个框与引导列的左下角对齐。谢谢你的帮助。

问题是列没有定义高度。

【问题讨论】:

  • 相对的父级,absokute 和 left:0 和 bottom:0 的框
  • 发布您的代码伙伴。所以我们可以帮助你。 :)
  • 问题是 .col-6-md 没有定义的高度...好的,我会发布
  • 您需要使两列的高度相同。然后放置绝对位置的按钮。 Here 是另一个对您有帮助的帖子。

标签: html css twitter-bootstrap vertical-alignment


【解决方案1】:

您可以将列设置为 flexbox 并将元素对齐到末尾。

.row {
  background: red;
}

.col-6-md {
  background: lightblue;
  height: 200px;
  display: flex;
}

.bottom {
  background: green;
  align-self: flex-end;
  width: 100px;
  height: 50px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
  <div class="col-6-md">
    <div class="bottom">Bottom</div>
  </div>
</div>

【讨论】:

  • 哦,我发现了问题。高度必须保持灵活。
【解决方案2】:

在 Bootstrap 4 中,您可以在列本身上使用 mt-auto 将项目与底部对齐。默认情况下它应该已经左对齐了

【讨论】:

    【解决方案3】:

    .bottomdiv {
        border: 1px solid red;
        height: 50px;
        width: 50px;
        position:absolute;
        left:0;
        bottom:0;
    }
    .col-md-6.col-sm-6.col-xs-6 {
        display: table-cell;
        height: auto;
        border: 1px solid black;
        float: none;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <div class="container">
        <div class="row">
           <div class="parent">
            <div class="col-md-6 col-sm-6 col-xs-6">
                 <div class="bottomdiv">
                 </div>             
            </div>
            <div class="col-md-6 col-sm-6 col-xs-6">
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
            </div>
        </div>
    </div></div>

    【讨论】:

      【解决方案4】:

      您也可以尝试使用绝对 CSS 功能

      .bottom {
         position: absolute;
         bottom: 0;
         left: 0;
      }
      

      然后检查位置,改变它以适应你

      【讨论】:

        【解决方案5】:

        在 Bootstrap 4 中

        对于整行中的所有列,在

        上使用 align-items-end

        对于单个列,我们在 col

        align-self-end

        文档:https://getbootstrap.com/docs/4.0/utilities/flex/#align-items

        【讨论】:

          【解决方案6】:

          如果你不想玩 css 你可以设置:

          class="mb-0"

          它将边距底部设置为零,并且应该将您的内容放到其所在单元格的底部 您可以以类似的方式将其对齐到其他方向:mb、mt、mr、ml

          【讨论】:

            猜你喜欢
            • 2014-12-03
            • 2019-02-08
            • 1970-01-01
            • 1970-01-01
            • 2014-12-02
            • 2019-07-03
            • 2018-04-03
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多