CSS force image resize and keep aspect ratio

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

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

\"\"

23条回答
  •  难免孤独
    2020-11-22 11:00

    There is no standard way to preserve aspect ratio for images with width, height and max-width specified together.

    So we are forced either to specify width and height to prevent page “jumps” during loading images, or to use max-width and not specify dimensions for images.

    Specifying just width (without height) typically makes not much sense, but you can try to override the height HTML-attribute by adding a rule like IMG {height: auto; } into your stylesheet.

    See also the related Firefox bug 392261.

提交回复
热议问题