CSS force image resize and keep aspect ratio

前端 未结 23 1110
野趣味
野趣味 2020-11-22 10:04

I am working with images, and I ran across a problem with aspect ratios.

\"\"

23条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 11:01

    I would suggest for a responsive approach the best practice would be using the Viewport units and min/max attributes as follows:

    img{
      display: block;
      width: 12vw;
      height:12vw;
      max-width:100%;
      min-width:100px;
      min-height:100px;
      object-fit:contain;
    }
    

提交回复
热议问题