csshtmlalignment

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


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.


Solution

  • 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.