CSS 如何将图像对齐到 div 的底部(在引导程序中)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15568829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:08:38  来源:igfitidea点击:

How do I align images to the bottom of a div (in bootstrap)?

csstwitter-bootstrap

提问by Sheldon

I would like to be able to align different sized images to the bottom of a div.

我希望能够将不同大小的图像对齐到 div 的底部。

I have the following markup:

我有以下标记:

<div class="container">
  <div class="container">
    <div class="footer-images">
      <a href="link1"><img src="img1"></a>
      <a href="link2"><img src="img2"></a>
      <a href="link3"><img src="img3"></a>
    </div>
  </div>
  <div class="container">
    <div class="copyright">
      <p>? Some Company YYYY</p>
    </div>
  </div>
</div>

I can't figure out how to have all the images aligned to the bottom of the footer-images div. Any help would be greatly appreciated.

我不知道如何将所有图像对齐到页脚图像 div 的底部。任何帮助将不胜感激。

采纳答案by Prashobh

try this

尝试这个

 .footer-images img{
        vertical-align:bottom;
        border:0;
        }

回答by Kane

Does this help?

这有帮助吗?

<style type="text/css">
.footer-images {
    margin: auto;
    display: block;
    position: absolute;
    bottom: 0;
}
.footer-images .copyright {
    text-align: center;
}
</style>

Using this HTML

使用这个 HTML

<div class="container">
  <div class="container">
    <div class="footer-images">
      <a href="link1"><img src="http://placehold.it/350x150"></a>
      <a href="link2"><img src="http://placehold.it/640x480"></a>
      <a href="link3"><img src="http://placehold.it/120x120"></a>
      <div class="container">
        <div class="copyright">
          <p>? Some Company YYYY</p>
        </div>
      </div>
    </div>
  </div>
</div>

回答by FreshSnow

In Bootstrap v4 you can use the class align-items-endto achieve bottom alignment in a div. You can use this class on the row or on the column.

在 Bootstrap v4 中,您可以使用该类align-items-end在 div 中实现底部对齐。您可以在行或列上使用此类。

Example with all column content aligned to the bottom.

所有列内容都与底部对齐的示例。

<div class="container">
  <div class="row align-items-end">
    <div class="col">
      One of three columns
    </div>
    <div class="col">
      One of three columns
    </div>
    <div class="col">
      One of three columns
    </div>
  </div>
</div>

Example with first column top, second colum middle and third colunm bottom alignment.

第一列顶部、第二列中间和第三列底部对齐的示例。

<div class="container">
  <div class="row">
    <div class="col align-self-start">
      One of three columns
    </div>
    <div class="col align-self-center">
      One of three columns
    </div>
    <div class="col align-self-end">
      One of three columns
    </div>
  </div>
</div>

Source: Bootstrap documentation.

来源:Bootstrap 文档

回答by Rohit Azad

used to this css and apply

习惯了这个css并应用

.footer-images img{
width:xxpx;
height:xxpx;           // add here your style as like with height border etc.
vertical-align:top;
border:0;
}

More about bootstrap

更多关于引导程序

回答by Pavel Novák

It would be enough:

就足够了:

margin-top: auto; 

See https://jsfiddle.net/d3jau1gx/

https://jsfiddle.net/d3jau1gx/