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

后端 未结 3 807
粉色の甜心
粉色の甜心 2020-12-05 06:17

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:

相关标签:
3条回答
  • 2020-12-05 06:55

    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.

    0 讨论(0)
  • 2020-12-05 07:04
    < img style="vertical-align: bottom" src="blah.png" >
    

    Works for me. Inside a parallax div as well.

    0 讨论(0)
  • 2020-12-05 07:17

    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;

    0 讨论(0)
提交回复
热议问题