HTML image bottom alignment inside DIV container

后端 未结 4 1729
执笔经年
执笔经年 2020-12-13 17:46

I have a div tag with a fixed height. Most of the images have the same height and width.

I want to align the images at the bottom of the div so that they are nicely

4条回答
  •  无人及你
    2020-12-13 18:05

    with some proportions

    div {
      position: relative;
      width: 100%;
      height: 100%;
    }
    

    's with their own proportions

    img {
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      width: auto; /* to keep proportions */
      height: auto; /* to keep proportions */
      max-width: 100%; /* not to stand out from div */
      max-height: 100%; /* not to stand out from div */
      margin: auto auto 0; /* position to bottom and center */
    }
    

提交回复
热议问题