CSS: 100% width or height while keeping aspect ratio?

前端 未结 14 2641
粉色の甜心
粉色の甜心 2020-11-28 21:05

Currently, with STYLE, I can use width: 100% and auto on the height (or vice versa), but I still can\'t constrain the image into a specific positio

14条回答
  •  一个人的身影
    2020-11-28 21:55

    Use JQuery or so, as CSS is a general misconception (the countless questions and discussions here about simple design goals show that).

    It is not possible with CSS to do what you seem to wish: image shall have width of 100%, but if this width results in a height that is too large, a max-height shall apply - and of course the correct proportions shall be preserved.

提交回复
热议问题