Vertically align an image inside a div with responsive height

后端 未结 10 1912
遇见更好的自我
遇见更好的自我 2020-11-22 02:47

I have the following code which sets up a container which has a height that changes with the width when the browser is re-sized (to maintain a square aspect ratio).

10条回答
  •  暖寄归人
    2020-11-22 03:24

    Try

    Html

    CSS

    .img-container {
        position: absolute;
        top: 0;
        left: 0;
    height:0;
    padding-bottom:100%;
    }
    .img-container img {
    width:100%;
    }
    

提交回复
热议问题