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

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

    Not to jump into an old issue, but...

    #container img {
          max-width:100%;
          height:auto !important;
    }
    

    Even though this is not proper as you use the !important override on the height, if you're using a CMS like WordPress that sets the height and width for you, this works well.

提交回复
热议问题