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

前端 未结 14 2528
粉色の甜心
粉色の甜心 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:53

    I think this is what your looking for, i was looking for it my self, but then i remembered it again befor i found the code.

    background-repeat: repeat-x;
    background-position: top;
    background-size:auto;
    background-attachment: fixed;
    

    digital evolution is on its way.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题