CSS类align-self-end不起作用 [英] CSS class align-self-end not working

查看:789
本文介绍了CSS类align-self-end不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-md-3">
  <div class="card bg-dark text-white">
    <img class="card-img" src="http://via.placeholder.com/300x340" alt="Card image">
    <div class="card-img-overlay">
      <h5 class="card-title">Title</h5>
      <h3 class="card-text font-weight-bold"><span class="mr-auto">Some other title here</span></h3>
      <div class="align-self-end">Text I want at bottom</div>
    </div>
  </div>
</div>

我无法通过将此类align-self-end应用于图像底部来获取最后一个div中的文本.我知道flex已按列方向应用于.card-img-overlay div,那么为什么我无法将div移到图像的底部?

I am unable to get the text in the last div by applying this class align-self-end to the bottom of the image. I understand that flex has been applied to the .card-img-overlay div with the direction of column then why am I unable to get the div to the bottom of the image?

推荐答案

card-img-overlay div不是display:flex.

您可以通过向其中添加d-flex flex-column类,然后使用mt-auto将文本推到底部来完成此操作.

You can do this by adding the d-flex flex-column classes to it, and use mt-auto to push the text to the bottom.

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

<div class="card bg-dark text-white">
       <img class="card-img" src="http://via.placeholder.com/300x340" alt="Card image">
       <div class="card-img-overlay d-flex flex-column">
            <h5 class="card-title">Title</h5>
            <h3 class="card-text font-weight-bold"><span class="mr-auto">Some other title here</span></h3>
            <div class="mt-auto">Text I want at bottom</div>
       </div>
</div>

这篇关于CSS类align-self-end不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆