Make image fill div completely without stretching

后端 未结 13 1725
情话喂你
情话喂你 2020-11-30 04:22

I have large images of varying dimensions that need to completely fill 240px by 300px containers in both dimensions. Here is what I got right now, which only works for one d

13条回答
  •  無奈伤痛
    2020-11-30 04:45

    Here is another solution I found, that no need to seperate portraid or landscape or scripting.

      

    CSS

    .container{
      position: relative;
      width: 500px;
      height: 300px;
      margin-top: 30px;
      background: #4477bb;
    }
    .pic{
        max-width: 100%;
        width: auto;
        max-height: 100%;
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        margin: auto;
    }
    

    Here it is, it works well...

    https://jsfiddle.net/efirat/17bopn2q/2/

提交回复
热议问题