max-height AND max-width with CSS only

前端 未结 6 1400
无人共我
无人共我 2021-02-02 07:43

First post for me here.

I\'m using a div to crop thumbnail images all in the same proportions (180wx170h). I\'m getting stuck when dealing with portrait as well as land

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-02 08:25

    You could try

    .crop img {max-height:170px; max-width:180px;}
    

    Since max-height and max-width are maxima, it should work. The browser will make the image as big as possible, without going over your dimensions.

    Note that this is untested, but based on this W3Schools page.

    Hope this helps!!

提交回复
热议问题