如何在div的底部放置图像?

时间:2013-07-29 21:15:40

标签: css html alignment

我希望html图像与div标签的底部齐平。我似乎无法找到实现这一目标的方法。

这是我的HTML:

<div class="span8">
  <img src="/img/play-shot1.jpg" class="text-center shadow">
</div>

问题是div嵌套在其他具有填充或边距的div中。

3 个答案:

答案 0 :(得分:60)

为包装div标签添加相对定位,然后将图像绝对定位在其中:

CSS:

.div-wrapper {
    position: relative;
    height: 300px;
    width: 300px;
}

.div-wrapper img {
    position: absolute;
    left: 0;
    bottom: 0;
}

HTML:

<div class="div-wrapper">
    <img src="blah.png"/>
</div>

现在图像位于div的底部。

答案 1 :(得分:3)

使用flexbox:

HTML:

<div class="wrapper">
    <img src="pikachu.gif"/>
</div>

CSS:

.wrapper {
    height: 300px;
    width: 300px;
    display: flex;
    align-items: flex-end;
}

根据对另一个答案的某些评论的要求,图像也可以justify-content: center;水平居中

答案 2 :(得分:0)

< img style="vertical-align: bottom" src="blah.png" >

为我工作。在视差div内。

相关问题