Vertically Center Responsive Image

前端 未结 3 2152
甜味超标
甜味超标 2020-12-29 14:03

I am wondering if there is a simple way to vertically center a responsive image.

Please refer to the following jsFiddle: http://jsfiddle.net/persianturtle/yawTb/1/

3条回答
  •  醉酒成梦
    2020-12-29 14:20

    The solution you've got works for old browsers but in the near future (right now has around the 80% of the browser support) you can do this, a much simpler and elegant solution:

    .container img{
      width: 100%;
      height: auto;
    }
    @supports(object-fit: cover){
        .container img{
          height: 100%;
          object-fit: cover;
          object-position: center center;
        }
    }
    

提交回复
热议问题