CSS force image resize and keep aspect ratio

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

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

\"\"

23条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 10:58

    img {
      display: block;
      max-width:230px;
      max-height:95px;
      width: auto;
      height: auto;
    }

    This image is originally 400x400 pixels, but should get resized by the CSS:

    This will make image shrink if it's too big for specified area (as downside, it will not enlarge image).

提交回复
热议问题