How to center an image horizontally and align it to the bottom of the container?

前端 未结 7 1526
执念已碎
执念已碎 2021-01-31 15:29

How can I center an image horizontally and aligned to the bottom of the container at the same time?

I have been able to center the image horizontally by its self. I hav

7条回答
  •  迷失自我
    2021-01-31 16:09

    This is tricky; the reason it's failing is that you can't position via margin or text-align while absolutely positioned.

    If the image is alone in the div, then I recommend something like this:

    .image_block {
        width: 175px;
        height: 175px;
        line-height: 175px;
        text-align: center;
        vertical-align: bottom;
    }
    

    You may need to stick the vertical-align call on the image instead; not really sure without testing it. Using vertical-align and line-height is going to treat you a lot better, though, than trying to mess around with absolute positioning.

提交回复
热议问题