How do I position an image at the bottom of div?

CssHtmlAlignment

Css Problem Overview


I want an html image to be flush with the bottom of a div tag. I can't seem to find a way to accomplish this.

Here is my HTML:

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

The problem is that the div is nested within other divs that have padding or margins.

Css Solutions


Solution 1 - Css

Add relative positioning to the wrapping div tag, then absolutely position the image within it like this:

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>

Now the image sits at the bottom of the div.

Solution 2 - Css

Using flexbox:

HTML:

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

CSS:

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

As requested in some comments on another answer, the image can also be horizontally centred with justify-content: center;

Solution 3 - Css

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

Works for me. Inside a parallax div as well.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDustin LeeView Question on Stackoverflow
Solution 1 - CssMatt LambertView Answer on Stackoverflow
Solution 2 - CssajrussellaudioView Answer on Stackoverflow
Solution 3 - CssatomkeyView Answer on Stackoverflow