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

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

    Its best to use auto on the dimension that should respect the aspect ratio. If you do not set the other property to auto, most browsers nowadays will assume that you want to respect the aspect ration, but not all of them (IE10 on windows phone 8 does not, for example)

    width: 100%;
    height: auto;
    

提交回复
热议问题